can-color
v0.1.0
Published
Detect whether a terminal supports color
Maintainers
Readme
can-color
Detect whether a terminal supports color. The minimal fork of chalk/supports-color, with some differents.
- ONLY supports
--[no-]-colorflag - JUST return boolean, no information about color supports level.
- You MUST create the detector manually.
Install
npm install can-colorUsage
import { canColor } from "can-color";
if (canColor(process.stdout)) {
console.log("Terminal stdout supports color");
}API
canColor(stream?, sniffFlags?)
Return: boolean
Detect whether a terminal supports color.
stream?
Type: WriteStream
sniffFlags?
Type: boolean
Info
It obeys the --color and --no-color CLI flags.
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.
