Skip to content

Adjust ANSI colors in logs and console for theme legibility - #10060

Open
awaisdev5765 wants to merge 2 commits into
flutter:masterfrom
awaisdev5765:fix/ansi-colors-contrast-theme
Open

awaisdev5765 wants to merge 2 commits into
flutter:masterfrom
awaisdev5765:fix/ansi-colors-contrast-theme

Conversation

@awaisdev5765

@awaisdev5765 awaisdev5765 commented Oct 30, 2026 •

Copy link
Copy Markdown

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:

  • Adds an optional backgroundColor parameter to textSpansFromAnsi and ansiToColor.
  • All console/logging call sites pass the theme surface color (theme.colorScheme.surface).
  • When a foreground ANSI color's contrast ratio against that background is below 3:1, it is blended toward black (on a light background) or white (on a dark background) to restore legibility. Colors that already have sufficient contrast are left untouched, so common ANSI colors like red or blue look exactly as before.
  • Background ANSI colors are not adjusted — a background that blends into the surface does not harm legibility.
  • Adds unit tests covering the adjustment behavior (low-contrast light/dark cases, high-contrast passthrough, and no-background passthrough).

Test coverage

  • New tests in packages/devtools_app/test/shared/primitives/utils_test.dart.
  • dart format passes on all touched files.

Tests couldn't run locally (local SDK version constraints) — CI should pick them up on this PR.

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
@awaisdev5765
awaisdev5765 requested review from a team and bkonyi as code owners October 30, 2026 13:55
@awaisdev5765
awaisdev5765 requested review from srawlins and removed request for a team October 30, 2026 13:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/devtools_app/lib/src/shared/primitives/utils.dart
Per code review feedback and the DevTools style guide.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ansi color in logging page does not respect light / dark theme

1 participant