c65744f436440058a0fd715d83bce76e88ade548ddf0fe6be141f07e0b83ad1a645173677297dcce2c320c4855b9db4155a674cef84370e70db4feec333879 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 --save supports-color
  6. ```
  7. ## Usage
  8. ```js
  9. var supportsColor = require('supports-color');
  10. if (supportsColor) {
  11. console.log('Terminal supports color');
  12. }
  13. if (supportsColor.has256) {
  14. console.log('Terminal supports 256 colors');
  15. }
  16. if (supportsColor.has16m) {
  17. console.log('Terminal supports 16 million colors (truecolor)');
  18. }
  19. ```
  20. ## API
  21. Returns an `object`, or `false` if color is not supported.
  22. The returned object 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`: 16 million (truecolor) support
  26. ## Info
  27. It obeys the `--color` and `--no-color` CLI flags.
  28. For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
  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. ## License
  34. MIT © [Sindre Sorhus](http://sindresorhus.com)