From d99213289f9abe6daeefa50cde67634d9ea6eeed Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sun, 20 Sep 2026 22:15:05 +0000 Subject: [PATCH] Honor the effective terminal color level in activity charts (#46897) ## Why Activity charts bypassed the terminal color adjustments used elsewhere in the TUI, so Windows Terminal could receive a low-color fallback despite supporting truecolor. ## What changed Use `effective_stdout_color_level()` when building the token activity palette so it honors the existing terminal adjustments and `FORCE_COLOR` override handling. ## Testing Add a regression test with scoped terminal colors that asserts the current palette uses color and snapshots all five daily activity levels with RGB colors. GitOrigin-RevId: c5a474bacb1416df754d71285106926f46a38e09 --- .../src/analytics/activity_chart/palette.rs | 4 +-- .../analytics/activity_chart/palette_tests.rs | 28 +++++++++++++++++++ ...e_uses_effective_terminal_color_level.snap | 10 +++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 codex-rs/tui/src/analytics/activity_chart/snapshots/codex_tui__analytics__activity_chart__palette__tests__current_palette_uses_effective_terminal_color_level.snap diff --git a/codex-rs/tui/src/analytics/activity_chart/palette.rs b/codex-rs/tui/src/analytics/activity_chart/palette.rs index 6be694dcd0..5ac415d572 100644 --- a/codex-rs/tui/src/analytics/activity_chart/palette.rs +++ b/codex-rs/tui/src/analytics/activity_chart/palette.rs @@ -14,7 +14,7 @@ use crate::terminal_palette::StdoutColorLevel; use crate::terminal_palette::best_color_for_level; use crate::terminal_palette::default_bg; use crate::terminal_palette::default_fg; -use crate::terminal_palette::stdout_color_level; +use crate::terminal_palette::effective_stdout_color_level; // In low-color terminals we distinguish empty vs active cells by glyph (a // width-matched filled/hollow pair). In truecolor terminals the grid uses a @@ -40,7 +40,7 @@ impl TokenActivityPalette { Self::from_parts( default_fg(), default_bg(), - stdout_color_level(), + effective_stdout_color_level(), theme_activity_style(), ) } diff --git a/codex-rs/tui/src/analytics/activity_chart/palette_tests.rs b/codex-rs/tui/src/analytics/activity_chart/palette_tests.rs index 458f950f32..e46bd0ad5d 100644 --- a/codex-rs/tui/src/analytics/activity_chart/palette_tests.rs +++ b/codex-rs/tui/src/analytics/activity_chart/palette_tests.rs @@ -3,6 +3,34 @@ use crate::terminal_palette::rgb_color; use pretty_assertions::assert_eq; use ratatui::style::Modifier; +#[test] +fn current_palette_uses_effective_terminal_color_level() { + let theme = + crate::render::highlight::resolve_theme_by_name("ada", /*codex_home*/ None).unwrap(); + crate::render::highlight::set_syntax_theme(theme); + crate::terminal_palette::with_test_default_colors( + crate::terminal_probe::DefaultColors { + fg: (240, 240, 240), + bg: (0, 0, 0), + }, + || { + let palette = TokenActivityPalette::current(); + assert!(palette.uses_color); + let legend = (0..5) + .map(|level| { + format!( + "{} {:?}", + palette.glyph(TokenActivityView::Daily, level), + palette.for_level(level).fg, + ) + }) + .collect::>() + .join("\n"); + insta::assert_snapshot!(legend); + }, + ); +} + #[test] fn truecolor_palette_blends_theme_accent_against_dark_background() { let default_fg = Some((240, 240, 240)); diff --git a/codex-rs/tui/src/analytics/activity_chart/snapshots/codex_tui__analytics__activity_chart__palette__tests__current_palette_uses_effective_terminal_color_level.snap b/codex-rs/tui/src/analytics/activity_chart/snapshots/codex_tui__analytics__activity_chart__palette__tests__current_palette_uses_effective_terminal_color_level.snap new file mode 100644 index 0000000000..bd5ed35edb --- /dev/null +++ b/codex-rs/tui/src/analytics/activity_chart/snapshots/codex_tui__analytics__activity_chart__palette__tests__current_palette_uses_effective_terminal_color_level.snap @@ -0,0 +1,10 @@ +--- +source: tui/src/analytics/activity_chart/palette_tests.rs +assertion_line: 29 +expression: legend +--- +■ Some(Rgb(33, 33, 33)) +■ Some(Rgb(20, 47, 56)) +■ Some(Rgb(39, 90, 107)) +■ Some(Rgb(64, 146, 173)) +■ Some(Rgb(95, 215, 255))