feat(tui): fallback to active theme when configured theme is unavailable

This commit is contained in:
Felipe Coury
2026-02-10 21:33:49 -03:00
parent 8c4bfa78f7
commit c510eec9f8

View File

@@ -194,12 +194,16 @@ pub(crate) fn build_theme_picker_params(
let entries = highlight::list_available_themes(codex_home);
let codex_home_owned = codex_home.map(|p| p.to_path_buf());
// Resolve the effective theme name: honor explicit config, fall back to
// the auto-detected default so the picker pre-selects even when no theme
// is configured.
let effective_name = current_name
.map(str::to_string)
.unwrap_or_else(highlight::current_theme_name);
// Resolve the effective theme name: honor explicit config only when it is
// currently available; otherwise fall back to the active runtime theme so
// opening `/theme` does not auto-preview an unrelated first entry.
let effective_name = if let Some(name) = current_name
&& entries.iter().any(|entry| entry.name == name)
{
name.to_string()
} else {
highlight::current_theme_name()
};
// Track the index of the current theme so we can pre-select it.
let mut initial_idx = None;
@@ -407,4 +411,19 @@ mod tests {
assert_eq!(subtitle, PREVIEW_FALLBACK_SUBTITLE);
}
#[test]
fn unavailable_configured_theme_falls_back_to_active_theme_selection() {
let active_theme = highlight::current_theme_name();
let params = build_theme_picker_params(Some("not-a-real-theme"), None, Some(120));
let selected_idx = params
.initial_selected_idx
.expect("expected selected index for active fallback theme");
let selected_name = params.items[selected_idx]
.search_value
.as_deref()
.expect("expected search value to contain canonical theme name");
assert_eq!(selected_name, active_theme);
}
}