Skip to content

fix(tui): make the model-line badge text readable on the accent color#116

Merged
BunsDev merged 1 commit into
mainfrom
fix/badge-contrast
Jun 24, 2026
Merged

fix(tui): make the model-line badge text readable on the accent color#116
BunsDev merged 1 commit into
mainfrom
fix/badge-contrast

Conversation

@BunsDev

@BunsDev BunsDev commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

The mode badge on the input header (KITTY/BUILD/PLAN/…) and the /connect pill rendered their text with .fg(Color::Black).add_modifier(Modifier::BOLD). Color::Black is ANSI index 0, and many terminals render bold + indexed black as "bright black" (gray) — which washes out against the violet/blue/amber accent background. That's the low-contrast badge text that was reported.

Fix

Add readable_fg_on(bg) (in app.rs) and use it for both badge spans. It returns an explicit Color::Rgb black or white — RGB colors aren't subject to bold-brightening, so the text stays solid — choosing the higher-contrast option by WCAG relative luminance.

For the three current accents it resolves to true black, which is the higher-contrast choice every time:

accent black white
violet (build) 4.96 4.23
blue (plan) 6.02 3.49
amber (explore) 12.24 1.72

It auto-flips to white if a darker accent is ever added, so it stays correct as the palette changes.

Before / after

BEFORE — bold + indexed black brightens to gray on the violet badge.
AFTER — solid true-RGB black, legible.

Testing

  • cargo check -p claurst-tui passes.
  • Verified the helper's branch selection numerically (table above).
  • Only the two model-line badge spans were touched; other unrelated Color::Black spans in render.rs are left as-is.

🤖 Generated with Claude Code

The mode badge (e.g. `KITTY`/`BUILD`) and the `/connect` pill styled their
text with `.fg(Color::Black).add_modifier(Modifier::BOLD)`. `Color::Black`
is ANSI index 0, and many terminals render *bold + indexed black* as
"bright black" (gray), which washes out against the violet/blue/amber
accent background — the reported low-contrast badge.

Add `readable_fg_on(bg)`, which returns an explicit `Color::Rgb` black or
white chosen by WCAG relative-luminance contrast. RGB colors aren't subject
to bold-brightening, so the badge text stays solid. For all three current
accents it resolves to true black (contrast 4.96 / 6.02 / 12.24 vs white's
4.23 / 3.49 / 1.72), and it auto-flips to white if a darker accent is added.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 24, 2026 20:49
@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Jun 24, 2026 8:49pm

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Improves TUI badge text contrast on accent-colored backgrounds by avoiding ANSI indexed black (which many terminals brighten under bold) and instead selecting an explicit RGB black/white foreground based on relative luminance.

Changes:

  • Add readable_fg_on(bg) helper to choose an explicit RGB foreground color for a given RGB background.
  • Update the input header mode badge and /connect pill to use readable_fg_on(app.accent_color) for their foreground styling.
  • Adjust render.rs imports to include the new helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src-rust/crates/tui/src/render.rs Uses readable_fg_on() for the mode badge and /connect pill foreground to keep text readable on accent backgrounds.
src-rust/crates/tui/src/app.rs Introduces readable_fg_on() helper that selects explicit RGB black/white using WCAG-style luminance math.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1629 to +1635
pub fn readable_fg_on(bg: Color) -> Color {
let (r, g, b) = match bg {
Color::Rgb(r, g, b) => (r, g, b),
// Non-RGB backgrounds (themes/indexed): default to black, which reads
// on the light/mid accent tones used here.
_ => return Color::Rgb(0, 0, 0),
};
/// black into low-contrast gray — the cause of the washed-out badge text. The
/// choice is made by comparing WCAG relative-luminance contrast ratios, so it
/// stays correct if the accent palette changes.
pub fn readable_fg_on(bg: Color) -> Color {
@BunsDev BunsDev merged commit 92efbe2 into main Jun 24, 2026
2 checks passed
@BunsDev BunsDev deleted the fix/badge-contrast branch June 24, 2026 20:57
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.

2 participants