Fix FORCE_COLOR to set exact level instead of minimum

Previously, FORCE_COLOR was used as a floor value and terminal
detection could return a higher level. For example, FORCE_COLOR=1
on a truecolor terminal would still give level 3.

Now when FORCE_COLOR is set to a specific level (1, 2, or 3), that
exact level is returned without further terminal capability checks.

Fixes #624
This commit is contained in:
Varun Chawla 2026-02-13 00:54:25 -08:00
parent aa06bb5ac3
commit 8255f6a1a5
3 changed files with 58 additions and 1 deletions

View file

@ -91,7 +91,15 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
return 0;
}
const min = forceColor || 0;
// When `FORCE_COLOR` is set to a specific level, return that level
// directly instead of using it as a minimum. This ensures that
// e.g. FORCE_COLOR=1 gives exactly level 1, not a higher level
// based on terminal capabilities.
if (forceColor !== undefined) {
return forceColor;
}
const min = 0;
if (env.TERM === 'dumb') {
return min;