Gathering detailed insights and metrics for color-support
Gathering detailed insights and metrics for color-support
Gathering detailed insights and metrics for color-support
Gathering detailed insights and metrics for color-support
A module which will endeavor to guess your terminal's level of color support.
npm install color-support
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
24 Stars
24 Commits
1 Forks
3 Watching
6 Branches
1 Contributors
Updated on 26 Nov 2022
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.5%
2,454,664
Compared to previous day
Last week
1.7%
14,152,608
Compared to previous week
Last month
7.1%
59,230,593
Compared to previous month
Last year
2.6%
671,009,112
Compared to previous year
1
A module which will endeavor to guess your terminal's level of color support.
This is similar to supports-color
, but it does not read
process.argv
.
If not in a node environment, not supported.
If stdout is not a TTY, not supported, unless the ignoreTTY
option is set.
If the TERM
environ is dumb
, not supported, unless the
ignoreDumb
option is set.
If on Windows, then support 16 colors.
If using Tmux, then support 256 colors.
Handle continuous-integration servers. If CI
or
TEAMCITY_VERSION
are set in the environment, and TRAVIS
is not
set, then color is not supported, unless ignoreCI
option is set.
Guess based on the TERM_PROGRAM
environ. These terminals support
16m colors:
iTerm.app
version 3.x supports 16m colors, below support 256MacTerm
supports 16m colorsApple_Terminal
supports 256 colorsMake a guess based on the TERM
environment variable. Any
xterm-256color
will get 256 colors. Any screen, xterm, vt100,
color, ansi, cygwin, or linux TERM
will get 16 colors.
If COLORTERM
environment variable is set, then support 16 colors.
At this point, we assume that color is not supported.
1var testColorSupport = require('color-support') 2var colorSupport = testColorSupport(/* options object */) 3 4if (!colorSupport) { 5 console.log('color is not supported') 6} else if (colorSupport.has16m) { 7 console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m') 8} else if (colorSupport.has256) { 9 console.log('\x1b[38;5;119m256 colors\x1b[0m') 10} else if (colorSupport.hasBasic) { 11 console.log('\x1b[31mbasic colors\x1b[0m') 12} else { 13 console.log('this is impossible, but colors are not supported') 14}
If you don't have any options to set, you can also just look at the flags which will all be set on the test function itself. (Of course, this doesn't return a falsey value when colors aren't supported, and doesn't allow you to set options.)
1var colorSupport = require('color-support') 2 3if (colorSupport.has16m) { 4 console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m') 5} else if (colorSupport.has256) { 6 console.log('\x1b[38;5;119m256 colors\x1b[0m') 7} else if (colorSupport.hasBasic) { 8 console.log('\x1b[31mbasic colors\x1b[0m') 9} else { 10 console.log('colors are not supported') 11}
You can pass in the following options.
isTTY
check.TERM=dumb
environ check.CI
environ check.process.env
.isTTY
check. Defaults to process.stdout
.TERM
checking. Defaults to env.TERM
.false
).alwaysReturn
to return an object for level 0, all other
options are ignored, since no checking is done if a level is
explicitly set.If no color support is available, then false
is returned by default,
unless the alwaysReturn
flag is set to true
. This is so that the
simple question of "can I use colors or not" can treat any truthy
return as "yes".
Otherwise, the return object has the following fields:
level
- A number from 0 to 3
0
- No color support1
- Basic (16) color support2
- 256 color support3
- 16 million (true) color supporthasBasic
- Booleanhas256
- Booleanhas16m
- BooleanYou can run the color-support
bin from the command line which will
just dump the values as this module calculates them in whatever env
it's run. It takes no command line arguments.
This is a spiritual, if not actual, fork of supports-color by the ever prolific Sindre Sorhus.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
42 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More