Skip to content

fix(tui): map AnsiValue indices through the ratatui bridge#274

Merged
emal-avala merged 1 commit into
mainfrom
fix/tui-ansivalue-bridge
May 4, 2026
Merged

fix(tui): map AnsiValue indices through the ratatui bridge#274
emal-avala merged 1 commit into
mainfrom
fix/tui-ansivalue-bridge

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

#271 added a 256-color downgrade path for Apple Terminal / screen-256color / tmux-256color via `color_emit::adapt`, which converts `Color::Rgb` to `Color::AnsiValue(n)` when the active `EmitMode` is `Ansi256`. The TUI bridge in `crates/cli/src/ui/tui.rs::theme_to_ratatui` did not handle the `AnsiValue` variant, so it fell through the wildcard arm to `Color::Reset`.

Result: on the very terminals #271 was meant to fix, every themed color the TUI consumes (status lines, REPL prompt, accent / muted / success / error / warning) was silently reset to terminal default. Visible regression on first-class targets.

Fix

Map `crossterm::style::Color::AnsiValue(n)` → `ratatui::style::Color::Indexed(n)`. ratatui emits that as SGR `38;5;n`, the same 256-color escape the downgrade path is targeting at the crossterm side.

Four-line patch.

Test plan

  • `cargo check --all-targets` clean on linux
  • `cargo clippy --all-targets -- -D warnings` clean
  • `cargo fmt --all -- --check` clean
  • Visible verification on Apple Terminal post-merge: themed status line and REPL prompt render with correct accent/muted/success/error colors instead of terminal default

#271's color downgrade path converts Color::Rgb to Color::AnsiValue(n)
when EmitMode is Ansi256 (Apple Terminal, screen-256color,
tmux-256color, NO_COLOR override). theme_to_ratatui in tui.rs only
handled truecolor and the 16 named ANSI variants; the AnsiValue
variant fell through the wildcard arm to Color::Reset.

Result: on the very terminals #271 was meant to fix, every themed
color the TUI consumes (status lines, REPL prompt, accent / muted /
success / error / warning) was silently reset to terminal default.

Map AnsiValue(n) -> ratatui::style::Color::Indexed(n). ratatui emits
that as SGR 38;5;n, matching the 256-color path the downgrade
targets at the crossterm side.
@emal-avala emal-avala merged commit 5cd1d56 into main May 4, 2026
14 checks passed
@emal-avala emal-avala deleted the fix/tui-ansivalue-bridge branch May 4, 2026 23:30
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