Skip to main content

vtcode_theme/
scheme.rs

1use vtcode_commons::ansi_capabilities::{ColorScheme, detect_color_scheme};
2
3use crate::color_math::relative_luminance;
4use crate::registry::theme_definition;
5use crate::types::DEFAULT_THEME_ID;
6
7/// Report whether a theme matches the detected terminal light/dark scheme.
8pub fn theme_matches_terminal_scheme(theme_id: &str) -> bool {
9    let scheme = detect_color_scheme();
10    let theme_is_light = is_light_theme(theme_id);
11
12    match scheme {
13        ColorScheme::Light => theme_is_light,
14        ColorScheme::Dark | ColorScheme::Unknown => !theme_is_light,
15    }
16}
17
18/// Report whether a built-in theme should be treated as a light theme.
19pub fn is_light_theme(theme_id: &str) -> bool {
20    theme_definition(theme_id)
21        .map(|theme| relative_luminance(theme.palette.background) > 0.5)
22        .unwrap_or(false)
23}
24
25/// Suggest a built-in theme that matches the current terminal scheme.
26pub fn suggest_theme_for_terminal() -> &'static str {
27    match detect_color_scheme() {
28        ColorScheme::Light => "vitesse-light",
29        ColorScheme::Dark | ColorScheme::Unknown => DEFAULT_THEME_ID,
30    }
31}