| 1 | # supports-color [](https://travis-ci.org/chalk/supports-color)
|
|---|
| 2 |
|
|---|
| 3 | > Detect whether a terminal supports color
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | ## Install
|
|---|
| 7 |
|
|---|
| 8 | ```
|
|---|
| 9 | $ npm install supports-color
|
|---|
| 10 | ```
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | ## Usage
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | const supportsColor = require('supports-color');
|
|---|
| 17 |
|
|---|
| 18 | if (supportsColor.stdout) {
|
|---|
| 19 | console.log('Terminal stdout supports color');
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | if (supportsColor.stdout.has256) {
|
|---|
| 23 | console.log('Terminal stdout supports 256 colors');
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | if (supportsColor.stderr.has16m) {
|
|---|
| 27 | console.log('Terminal stderr supports 16 million colors (truecolor)');
|
|---|
| 28 | }
|
|---|
| 29 | ```
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | ## API
|
|---|
| 33 |
|
|---|
| 34 | 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.
|
|---|
| 35 |
|
|---|
| 36 | The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
|
|---|
| 37 |
|
|---|
| 38 | - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
|
|---|
| 39 | - `.level = 2` and `.has256 = true`: 256 color support
|
|---|
| 40 | - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | ## Info
|
|---|
| 44 |
|
|---|
| 45 | It obeys the `--color` and `--no-color` CLI flags.
|
|---|
| 46 |
|
|---|
| 47 | Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
|---|
| 48 |
|
|---|
| 49 | Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | ## Related
|
|---|
| 53 |
|
|---|
| 54 | - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
|
|---|
| 55 | - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | ## Maintainers
|
|---|
| 59 |
|
|---|
| 60 | - [Sindre Sorhus](https://github.com/sindresorhus)
|
|---|
| 61 | - [Josh Junon](https://github.com/qix-)
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | ## License
|
|---|
| 65 |
|
|---|
| 66 | MIT
|
|---|