Visitar URL original
Fix: Treat a numeric `FORCE_COLOR` as an exact level by sindresorhus 路 Pull Request #688 路 chalk/chalk 路 GitHub
Skip to content

Fix: Treat a numeric FORCE_COLOR as an exact level - #688

Merged
sindresorhus merged 1 commit into
mainfrom
force-color-exact-level
Jul 25, 2026
Merged

sindresorhus merged 1 commit into
mainfrom
force-color-exact-level

Conversation

@sindresorhus

Copy link
Copy Markdown
Member

FORCE_COLOR was only used as a minimum level, so every non-zero value collapsed to whatever the environment detected. For example, FORCE_COLOR=1 in a truecolor terminal gave level 3.

A numeric FORCE_COLOR is now used as-is and overrides all other color support checks, which is what the readme already documented and what Node.js itself does. FORCE_COLOR=true and FORCE_COLOR= keep only enabling color and letting the level be detected, as in the https://force-color.org standard. The --color, --color=256, and --color=16m flags are unchanged.

A non-numeric value such as FORCE_COLOR=unicorn is now treated as unset instead of parsing to NaN.

Fixes #624

`FORCE_COLOR` was only used as a minimum level, so every non-zero value collapsed to whatever the environment detected. For example, `FORCE_COLOR=1` in a truecolor terminal gave level 3.

A numeric `FORCE_COLOR` is now used as-is and overrides all other color support checks, which is what the readme already documented and what Node.js itself does. `FORCE_COLOR=true` and `FORCE_COLOR=` keep only enabling color and letting the level be detected, as in the https://force-color.org standard. The `--color`, `--color=256`, and `--color=16m` flags are unchanged.

A non-numeric value such as `FORCE_COLOR=unicorn` is now treated as unset instead of parsing to `NaN`.

Fixes #624
@sindresorhus
sindresorhus merged commit e912931 into main Jul 25, 2026
4 checks passed
@sindresorhus
sindresorhus deleted the force-color-exact-level branch July 25, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

1 participant