color-support
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The color-support is an npm package created to guess the level of color support your terminal has. This JavaScript module helps in figuring out whether your terminal supports basic colors, 256 colors, or 16 million colors. It uses several parameters such as the Node environment, TTY status, 'TERM' environ, Windows or Tmux usage, and specific environment variables to make these determinations.
To use color-support in your application, you first need to install it using npm and then require it in your JavaScript file. Below is a basic example:
var testColorSupport = require('color-support');
var colorSupport = testColorSupport();
if (!colorSupport) {
console.log('color is not supported');
} else if (colorSupport.has16m) {
console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m');
} else if (colorSupport.has256) {
console.log('\x1b[38;5;119m256 colors\x1b[0m');
} else if (colorSupport.hasBasic) {
console.log('\x1b[31mbasic colors\x1b[0m');
} else {
console.log('this is impossible, but colors are not supported');
}
In the above code, an options object can optionally be passed to the testColorSupport
function. If no options are passed, the returned value will either be false
or an object with color-support information.
The color-support documentation can be found on the GitHub repository for this package at https://github.com/isaacs/color-support. The readme file that comes with the package has a detailed explanation of the module's usage and options. This includes the option to ignore the isTTY
check, TERM=dumb
environ check, and CI
environ check. It also explains the return value when no color support is available.