chalk/chalk

$FORCE_COLOR works only as either level 0 or 3

m15a opened this issue · 1 comments

m15a commented

I tried to override the level of color support using $FORCE_COLOR environment variable, but I got

> cat test.mjs
import { supportsColor } from 'chalk';
console.log("FORCE_COLOR:", process.env.FORCE_COLOR, "\tsupportsColor:", supportsColor);

> for i in 0 1 2 3; env FORCE_COLOR=$i node test.mjs; end
FORCE_COLOR: 0 	supportsColor: false
FORCE_COLOR: 1 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }
FORCE_COLOR: 2 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }
FORCE_COLOR: 3 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }

Chalk version: 5.3.0
Node version: 20.10.0

Note that my terminal is Alacritty and it supports truecolor, so the default color support level should be 3 in my environment.

m15a commented

Oh I see. If $COLORTERM=truecolor is set, even if $FORCE_COLOR is less than 3, supportsColor happens to be set to 3.

> set --global --export COLORTERM truecolor
> for i in 0 1 2 3; env FORCE_COLOR=$i node test.mjs; end
FORCE_COLOR: 0 	supportsColor: false
FORCE_COLOR: 1 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }
FORCE_COLOR: 2 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }
FORCE_COLOR: 3 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }

> set --erase COLORTERM
> for i in 0 1 2 3; env FORCE_COLOR=$i node test.mjs; end
FORCE_COLOR: 0 	supportsColor: false
FORCE_COLOR: 1 	supportsColor: { level: 1, hasBasic: true, has256: false, has16m: false }
FORCE_COLOR: 2 	supportsColor: { level: 2, hasBasic: true, has256: true, has16m: false }
FORCE_COLOR: 3 	supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true }