mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
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
This commit is contained in:
@@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!(legend);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truecolor_palette_blends_theme_accent_against_dark_background() {
|
||||
let default_fg = Some((240, 240, 240));
|
||||
|
||||
+10
@@ -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))
|
||||
Reference in New Issue
Block a user