Skip to content

[patch] Leave the terminal's color for a transparent foreground or background - #191

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/155-transparent-color
Oct 5, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/155-transparent-color

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #155

What was wrong

SpectreConsoleProvider.BuildStyleString wrote a color as #RRGGBB and ignored Color.A. As a result, Background = "Transparent" (ARGB 00FFFFFF) painted an opaque white block behind the text, and any zero-alpha color was drawn using its RGB channels.

Change

  • A foreground or background with A == 0 is left out of the markup, so the terminal's own color shows. This matches leaving the property unset.
  • Partial alpha (1–254) is drawn opaque, because a terminal cannot blend. This is now documented in the <remarks> on TextStyle.ForegroundColor and TextStyle.BackgroundColor.

Tests

Four new SpectreConsoleProviderTests run against a TrueColor test console. CreateProvider now takes an optional color system and still defaults to NoColors.

  • Background = "Transparent" writes exactly ESC[1;1HESC[38;2;255;255;0mHiESC[0m, the expected output from the issue.
  • BackgroundColor = Color.FromArgb(0, 0, 0, 0) writes no 48; parameter.
  • Foreground = "Transparent" writes no 38; parameter, and the background is still written.
  • Partial alpha is drawn opaque.

The first three failed before the fix. The full suite passes locally (247/247).

🤖 Generated with Claude Code

https://claude.ai/code/session_01GQx1vbckMdZECPqnBTXWek


Generated by Claude Code

…ckground

SpectreConsoleProvider built its markup from a color's RGB channels and
ignored alpha, so Background = "Transparent" (ARGB 00FFFFFF) painted an
opaque white block behind the text, and any zero-alpha color drew its RGB.
A color with zero alpha is now left out of the style, so the terminal's own
color shows; any other alpha is drawn opaque, since a terminal cannot blend.

Fixes #155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GQx1vbckMdZECPqnBTXWek

Copy link
Copy Markdown
Contributor Author

ci / .NET / Analyze & Release failed in the SonarCloud scanner, not in this change: POST https://api.sonarcloud.io/analysis/analyses failed with HTTP 502 while the scanner was creating the analysis. The tests and CodeQL passed on all three platforms on this commit. This PR only touches SpectreConsoleProvider.BuildStyleString, TextStyle docs and tests, and none of that is involved in the scanner's upload. I've re-run the failed job once. If it fails again the same way, I'll treat it as a real problem and look further.


Generated by Claude Code

@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit dd70e2a into main Oct 5, 2026
21 of 22 checks passed
@matt-edmondson
matt-edmondson deleted the fix/155-transparent-color branch October 6, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants