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

* Adjust ANSI colors in logs and console for theme legibility

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 #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 #6345

* Extract magic numbers in _adjustForContrast into named constants

Per code review feedback and the DevTools style guide.

* Add release note for ANSI color legibility improvements

* Remove unnecessary import from utils.dart

---------

Co-authored-by: awaisdev5765 <awaisdev5765@users.noreply.github.com>
Co-authored-by: Sam Rawlins <sam.rawlins@gmail.com>
7 files changed
tree: d0cc12b5f2142c27ca2364d35b972112f97ef1bf
  1. .agents/
  2. .gemini/
  3. .github/
  4. .vscode/
  5. _markdown_images/
  6. docs/
  7. packages/
  8. third_party/
  9. tool/
  10. .gitattributes
  11. .gitignore
  12. AGENTS.md
  13. analysis_options.yaml
  14. AUTHORS
  15. BETA_TESTING.md
  16. CLAUDE.md
  17. CODE_OF_CONDUCT.md
  18. CODEOWNERS
  19. CONTRIBUTING.md
  20. DEBUGGING.md
  21. devtools_options.yaml
  22. DOCUMENTATION.md
  23. flutter-candidate.txt
  24. LICENSE
  25. pubspec.lock
  26. pubspec.yaml
  27. README.md
  28. STYLE.md
  29. TESTING.md
  30. TRIAGE.md
README.md

Dart & Flutter DevTools

Build Status OpenSSF Scorecard

What is this?

Dart & Flutter DevTools is a suite of performance tools for Dart and Flutter.

Getting started

For documentation on installing and trying out DevTools, please see our docs.

Contributing and development

Contributions welcome! See our contributing page for an overview of how to build and contribute to the project.

Terms and Privacy

By using Dart DevTools, you agree to the Google Terms of Service. To understand how we use data collected from this service, see the Google Privacy Policy.