6ef388a93c5c4bbb57078ad84343df773366871a5239468ec1c1757b6dcea5e14d571261cd017a935bc493def5d5fc61009dfe680db01c55595a1ff2b9bc40 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color)
  2. > Detect whether a terminal supports color
  3. ## Install
  4. ```
  5. $ npm install supports-color
  6. ```
  7. ## Usage
  8. ```js
  9. const supportsColor = require('supports-color');
  10. if (supportsColor.stdout) {
  11. console.log('Terminal stdout supports color');
  12. }
  13. if (supportsColor.stdout.has256) {
  14. console.log('Terminal stdout supports 256 colors');
  15. }
  16. if (supportsColor.stderr.has16m) {
  17. console.log('Terminal stderr supports 16 million colors (truecolor)');
  18. }
  19. ```
  20. ## API
  21. Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
  22. The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
  23. - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
  24. - `.level = 2` and `.has256 = true`: 256 color support
  25. - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
  26. ## Info
  27. It obeys the `--color` and `--no-color` CLI flags.
  28. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
  29. Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
  30. ## Related
  31. - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
  32. - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
  33. ## Maintainers
  34. - [Sindre Sorhus](https://github.com/sindresorhus)
  35. - [Josh Junon](https://github.com/qix-)
  36. ---
  37. <div align="center">
  38. <b>
  39. <a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  40. </b>
  41. <br>
  42. <sub>
  43. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  44. </sub>
  45. </div>
  46. ---