Skip to main content

virtuoso_cli/tui/
theme.rs

1use ratatui::style::Color;
2
3/// UI color palette. All color access goes through `Theme` so `no_color` mode
4/// can fall back to `Modifier::REVERSED` for accessibility.
5pub struct Theme {
6    pub no_color: bool,
7    pub primary: Color,
8    pub accent: Color,
9    pub success: Color,
10    pub error: Color,
11    #[allow(dead_code)]
12    pub warning: Color,
13    pub text: Color,
14    pub text_dim: Color,
15    pub border: Color,
16    #[allow(dead_code)]
17    pub bg: Color,
18    pub bg_selected: Color,
19    pub surface: Color,
20}
21
22impl Default for Theme {
23    fn default() -> Self {
24        Self {
25            no_color: false,
26            primary: Color::Rgb(0, 184, 212),
27            accent: Color::Rgb(255, 193, 7),
28            success: Color::Rgb(76, 175, 80),
29            error: Color::Rgb(244, 67, 54),
30            warning: Color::Rgb(255, 152, 0),
31            text: Color::Rgb(224, 224, 224),
32            text_dim: Color::Rgb(120, 120, 120),
33            border: Color::Rgb(97, 97, 97),
34            bg: Color::Rgb(33, 33, 33),
35            bg_selected: Color::Rgb(42, 42, 55),
36            surface: Color::Rgb(60, 60, 72),
37        }
38    }
39}
40
41impl Theme {
42    /// Detect no_color from the `NO_COLOR` environment variable per https://no-color.org.
43    pub fn detect() -> Self {
44        let no_color = std::env::var_os("NO_COLOR").is_some();
45        Self {
46            no_color,
47            ..Self::default()
48        }
49    }
50
51    #[allow(dead_code)]
52    /// Force no_color on or off (from `--no-color` CLI flag).
53    pub fn with_no_color(mut self, no_color: bool) -> Self {
54        self.no_color = self.no_color || no_color;
55        self
56    }
57}