fix(theme/persist): apply custom colors only when theme == Custom; clear [tui.theme].colors/label when switching to built-in themes so startup doesn’t force Custom palette

This commit is contained in:
James Peter
2025-09-11 09:02:15 +10:00
parent 75d16b0d3a
commit 69e6cc16f5
2 changed files with 14 additions and 1 deletions
+8
View File
@@ -386,6 +386,14 @@ pub fn set_tui_theme_name(codex_home: &Path, theme: ThemeName) -> anyhow::Result
// Write `[tui.theme].name = "…"`
doc["tui"]["theme"]["name"] = toml_edit::value(theme_str);
// When switching away from the Custom theme, clear any lingering custom
// overrides so built-in themes render true to spec on next startup.
if theme != ThemeName::Custom {
if let Some(tbl) = doc["tui"]["theme"].as_table_mut() {
tbl.remove("label");
tbl.remove("colors");
}
}
// ensure codex_home exists
std::fs::create_dir_all(codex_home)?;
+6 -1
View File
@@ -57,7 +57,12 @@ impl Default for Theme {
/// Initialize the global theme from configuration
pub fn init_theme(config: &ThemeConfig) {
let mut theme = get_predefined_theme(config.name);
apply_custom_colors(&mut theme, &config.colors);
// Important: Only apply color overrides for the Custom theme.
// Built-in themes should render exactly as defined so that switching away
// from Custom does not keep stale custom overrides from config.
if matches!(config.name, ThemeName::Custom) {
apply_custom_colors(&mut theme, &config.colors);
}
// On some terminals (notably macOS Terminal.app with certain profiles),
// truecolor escape sequences may render incorrectly. Detect such cases