Repository navigation
Adjust ANSI colors in logs and console for theme legibility - #10060
Open
awaisdev5765 wants to merge 2 commits into
Open
awaisdev5765 wants to merge 2 commits into
awaisdev5765 wants to merge 2 commits into
Conversation
ANSI colors are fixed terminal colors, so some of them (e.g. ansi-black, ansi-white, ansi-bright-white) are effectively invisible against the corresponding light or dark themed background (see flutter#6345). textSpansFromAnsi now takes an optional background color, which all console/logging call sites pass as the theme surface. Foreground colors whose contrast ratio against that background is below 3:1 are blended toward black (on a light background) or white (on a dark background) to restore legibility; sufficiently contrasting colors are left untouched. Background ANSI colors are not adjusted since blending into the surface does not harm legibility. Adds unit tests for the contrast adjustment behavior. Fixes flutter#6345
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces contrast adjustment for ANSI terminal colors to ensure legibility against light or dark backgrounds in DevTools. It updates textSpansFromAnsi and ansiToColor to accept a background color, implements a contrast check using luminance, and blends low-contrast colors towards black or white. It also adds corresponding unit tests. Feedback suggests extracting magic numbers (like 3.0 and 0.6) in the contrast adjustment logic into descriptive named constants to improve readability and maintainability.
Per code review feedback and the DevTools style guide.
This branch has not been deployed
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.
Fixes #6345
Description
ANSI colors are fixed terminal colors, so some of them (e.g.
ansi-black,ansi-white,ansi-bright-white) are effectively invisible against the corresponding light or dark themed background, as shown in the screenshots in #6345.This PR:
backgroundColorparameter totextSpansFromAnsiandansiToColor.theme.colorScheme.surface).Test coverage
packages/devtools_app/test/shared/primitives/utils_test.dart.dart formatpasses on all touched files.Tests couldn't run locally (local SDK version constraints) — CI should pick them up on this PR.