Skip to content

Fix FORCE_COLOR to set exact level instead of minimum#672

Closed
veeceey wants to merge 1 commit intochalk:mainfrom
veeceey:fix/issue-624-force-color
Closed

Fix FORCE_COLOR to set exact level instead of minimum#672
veeceey wants to merge 1 commit intochalk:mainfrom
veeceey:fix/issue-624-force-color

Conversation

@veeceey
Copy link
Copy Markdown

@veeceey veeceey commented Feb 13, 2026

When FORCE_COLOR is set to a specific level like 1 or 2, the expected behavior is that the color support level is forced to exactly that value. However, FORCE_COLOR was being used as a floor/minimum value in _supportsColor, meaning terminal capability detection could still return a higher level.

For example, on a terminal with COLORTERM=truecolor, setting FORCE_COLOR=1 would still give level 3 because the truecolor check fires after the minimum is set.

The fix makes _supportsColor return the forced level directly when FORCE_COLOR is explicitly set, skipping the terminal detection logic entirely. This matches the expected semantics — "force" means force to this exact level, not "ensure at least this level."

Before:

FORCE_COLOR=1 (with COLORTERM=truecolor) => level 3
FORCE_COLOR=2 (with COLORTERM=truecolor) => level 3

After:

FORCE_COLOR=1 (with COLORTERM=truecolor) => level 1
FORCE_COLOR=2 (with COLORTERM=truecolor) => level 2

Fixes #624

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 chalk#624
@sindresorhus
Copy link
Copy Markdown
Member

@chalk chalk locked as spam and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$FORCE_COLOR works only as either level 0 or 3

2 participants