fix: respect FORCE_COLOR level by capping detected terminal capability#165
Closed
guoyangzhen wants to merge 1 commit intochalk:mainfrom
Closed
fix: respect FORCE_COLOR level by capping detected terminal capability#165guoyangzhen wants to merge 1 commit intochalk:mainfrom
guoyangzhen wants to merge 1 commit intochalk:mainfrom
Conversation
When FORCE_COLOR is explicitly set (e.g., FORCE_COLOR=1), the returned color level should be capped at the specified value. Previously, terminal detection would override FORCE_COLOR, making it impossible to reduce color support. Fixes chalk#131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #131
When
FORCE_COLORis explicitly set (e.g.,FORCE_COLOR=1), the returned color level should be capped at the specified value. Previously, terminal detection would overrideFORCE_COLOR, making it impossible to reduce color support.Problem
The issue:
forceColorwas used asmin(floor) but not ascap(ceiling). Terminal capability detection (COLORTERM=truecolor, TERM checks, etc.) would return higher levels without respecting the forced value.Fix
Add a
capvariable set toforceColorwhen explicitly provided, otherwiseInfinity. ApplyMath.min(detected_level, cap)at all early return points, ensuring the forced level is never exceeded while still allowing lower detected levels to pass through.Behavior after fix
FORCE_COLOR=0→ level 0 (no color)FORCE_COLOR=1→ level 1 max (basic 16 colors)FORCE_COLOR=2→ level 2 max (256 colors)FORCE_COLOR=3→ level 3 (truecolor, same as before)FORCE_COLOR→ detected level (same as before)