Skip to content

Convert direct terminal output to the detected color profile - #370

Merged
CLHatch merged 1 commit into
mainfrom
cli-color-profile
Nov 28, 2026
Merged

CLHatch merged 1 commit into
mainfrom
cli-color-profile

Conversation

@CLHatch

@CLHatch CLHatch commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What

Output DS2 writes straight to the terminal now uses the same color profile as its Bubble Tea views, so both show the same colors.

Why

Bubble Tea converts colors to the profile it detects. Direct output was always truecolor. When COLORTERM isn't set and the terminal doesn't answer DS2's query, the two disagreed:

  • The live compose view and -g showed 256-color stand-ins for an ANSI tint.
  • The final compose table and the log lines showed the tint's exact colors.

Changes

  • New console.ToProfile converts SGR color codes to the detected profile. console.ForTerminal fills in tints first, then converts.
    • Only colors change. Hyperlinks and other escape codes pass through.
    • Truecolor and no-color profiles are left as is.
    • A running TUI is left as is, because Bubble Tea converts per session.
  • Applied where text goes straight to the terminal:
    • console.Println, CLI tables, logger console messages and Display;
    • the compose viewport's main-screen dump and the static (redirected) compose output;
    • --config-show, the prune display, and --man. --man skips the conversion for Kitty placeholders, which carry their image ID in their color.
  • The compose viewport passes DS2's detected profile to Bubble Tea instead of letting it guess from TERM/COLORTERM.

Testing

  • go build, go vet, and tests for the changed packages. New TestToProfile covers truecolor, 256-color, no-color, plain text, hyperlinks, and the running-TUI case.
  • On a Linux test host under a pseudo-terminal with TERM=xterm-256color, --config-show emits 174 truecolor codes with COLORTERM=truecolor and 146 256-color codes without it.

Bubble Tea converts colors to the profile it detects, but output written
straight to the terminal was always truecolor, so without COLORTERM the
live compose view and -g looked different from the final table and the
log lines. Direct output now converts to DS2's detected profile too, and
the compose viewport uses that profile instead of guessing from
TERM/COLORTERM. A running TUI and Kitty image placeholders are left as is.
@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Sorry @CLHatch, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 23 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@CLHatch
CLHatch merged commit af8a856 into main Nov 28, 2026
6 checks passed
@CLHatch
CLHatch deleted the cli-color-profile branch November 28, 2026 06:49
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.

1 participant