supercode-harness 0.4.8

The optional native Supercode agent and tool harness
Documentation
//! P5-4 (§3.1 `capabilities.tui.theme`, D8 "themes"): the SEMANTIC theme
//! choice — which of the built-in named roles (accent, dim, error, …) a
//! renderer should map to actual terminal colors. Deliberately carries no
//! `ratatui::style::Color` (or any other terminal-library type) so this
//! stays part of the terminal-free view-model core; `crates/cli`'s
//! render layer owns the actual RGB/ANSI mapping.

/// A built-in theme name. `Dark` is the default (matches
/// `Config::tui_theme`'s `"dark"` default).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Theme {
    /// Default — matches most terminals' dark-background convention.
    #[default]
    Dark,
    /// Light-background terminal.
    Light,
}

impl Theme {
    /// Parse `capabilities.tui.theme`'s string value. Unknown values fall
    /// back to [`Theme::Dark`] rather than erroring — a themed cosmetic
    /// setting is never worth refusing to start the TUI over.
    pub fn parse(s: &str) -> Self {
        match s.to_ascii_lowercase().as_str() {
            "light" => Theme::Light,
            _ => Theme::Dark,
        }
    }

    /// The toggle [`crate::tui::Action::ToggleTheme`] cycles to.
    pub fn toggled(self) -> Self {
        match self {
            Theme::Dark => Theme::Light,
            Theme::Light => Theme::Dark,
        }
    }

    /// A short, human-readable name for the status line.
    pub fn label(self) -> &'static str {
        match self {
            Theme::Dark => "dark",
            Theme::Light => "light",
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parse_known_and_unknown() {
        assert_eq!(Theme::parse("light"), Theme::Light);
        assert_eq!(Theme::parse("LIGHT"), Theme::Light);
        assert_eq!(Theme::parse("dark"), Theme::Dark);
        assert_eq!(Theme::parse("bogus"), Theme::Dark);
        assert_eq!(Theme::parse(""), Theme::Dark);
    }

    #[test]
    fn toggle_round_trips() {
        assert_eq!(Theme::Dark.toggled(), Theme::Light);
        assert_eq!(Theme::Light.toggled(), Theme::Dark);
        assert_eq!(Theme::Dark.toggled().toggled(), Theme::Dark);
    }

    #[test]
    fn default_is_dark() {
        assert_eq!(Theme::default(), Theme::Dark);
    }
}