Skip to content

Honor FORCE_COLOR when terminfo has no setaf - #134406

Open
am11 wants to merge 2 commits into
dotnet:mainfrom
am11:patch-58
Open

am11 wants to merge 2 commits into
dotnet:mainfrom
am11:patch-58

Conversation

@am11

@am11 am11 commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

WriteSetColorString defers entirely to terminfo, so
Console.ForegroundColor writes nothing when the terminal offers no
setaf/setab, even with FORCE_COLOR=1.

env -u TERM FORCE_COLOR=1 ./app    # no escapes
FORCE_COLOR=1 ./app                # escapes

Fall back to standard SGR sequences only when color was explicitly
forced; when it is on merely because output is not redirected, an
absent capability still means no color. ResetColor gets a matching
ESC[0m.

This also overrides TERM=dumb, since FORCE_COLOR is the later and
equally explicit signal.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 22, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-console
See info in area-owners.md if you want to be subscribed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Console community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant