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
If not in a node environment, not supported.
If stdout is not a TTY, not supported, unless the
option is set.
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
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
iTerm.appversion 3.x supports 16m colors, below support 256
MacTermsupports 16m colors
Apple_Terminalsupports 256 colors
Make 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.
COLORTERM environment variable is set, then support 16 colors.
At this point, we assume that color is not supported.
var testColorSupport =var colorSupport =if !colorSupportconsoleelse if colorSupporthas16mconsoleelse if colorSupporthas256consoleelse if colorSupporthasBasicconsoleelseconsole
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.)
var colorSupport =if colorSupporthas16mconsoleelse if colorSupporthas256consoleelse if colorSupporthasBasicconsoleelseconsole
You can pass in the following options.
isTTYcheck. Defaults to
TERMchecking. Defaults to
alwaysReturnto 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,
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 support
1- Basic (16) color support
2- 256 color support
3- 16 million (true) color support
You 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.