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 | 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.
|
---|
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 | ---
|
---|
65 |
|
---|
66 | <div align="center">
|
---|
67 | <b>
|
---|
68 | <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>
|
---|
69 | </b>
|
---|
70 | <br>
|
---|
71 | <sub>
|
---|
72 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
---|
73 | </sub>
|
---|
74 | </div>
|
---|
75 |
|
---|
76 | ---
|
---|