Skip to main content

graphrag_cli/
theme.rs

1//! Color themes and styling for the TUI
2//!
3//! Provides consistent color schemes and style utilities across the application.
4
5use ratatui::style::{Color, Modifier, Style};
6
7/// Application color theme
8#[derive(Debug, Clone)]
9pub struct Theme {
10    /// Primary accent color (used for highlights)
11    pub primary: Color,
12    /// Secondary accent color
13    #[allow(dead_code)]
14    pub secondary: Color,
15    /// Success color (green)
16    pub success: Color,
17    /// Error color (red)
18    pub error: Color,
19    /// Warning color (yellow)
20    pub warning: Color,
21    /// Info color (blue)
22    pub info: Color,
23    /// Progress color (cyan)
24    pub progress: Color,
25    /// Background color
26    #[allow(dead_code)]
27    pub background: Color,
28    /// Foreground/text color
29    pub foreground: Color,
30    /// Border color (normal state)
31    pub border: Color,
32    /// Border color (focused state)
33    pub border_focused: Color,
34    /// Selection/highlight color
35    #[allow(dead_code)]
36    pub selection: Color,
37}
38
39impl Default for Theme {
40    fn default() -> Self {
41        Self {
42            primary: Color::Cyan,
43            secondary: Color::Blue,
44            success: Color::Green,
45            error: Color::Red,
46            warning: Color::Yellow,
47            info: Color::Blue,
48            progress: Color::Cyan,
49            background: Color::Black,
50            foreground: Color::White,
51            border: Color::DarkGray,
52            border_focused: Color::Cyan,
53            selection: Color::DarkGray,
54        }
55    }
56}
57
58impl Theme {
59    /// Create a light theme variant
60    #[allow(dead_code)]
61    pub fn light() -> Self {
62        Self {
63            primary: Color::Blue,
64            secondary: Color::Cyan,
65            success: Color::Green,
66            error: Color::Red,
67            warning: Color::Yellow,
68            info: Color::Blue,
69            progress: Color::Cyan,
70            background: Color::White,
71            foreground: Color::Black,
72            border: Color::Gray,
73            border_focused: Color::Blue,
74            selection: Color::LightBlue,
75        }
76    }
77
78    /// Get style for normal text
79    pub fn text(&self) -> Style {
80        Style::default().fg(self.foreground)
81    }
82
83    /// Get style for dimmed text
84    pub fn text_dim(&self) -> Style {
85        Style::default().fg(Color::DarkGray)
86    }
87
88    /// Get style for title text
89    pub fn title(&self) -> Style {
90        Style::default()
91            .fg(self.primary)
92            .add_modifier(Modifier::BOLD)
93    }
94
95    /// Get style for success messages
96    pub fn success(&self) -> Style {
97        Style::default().fg(self.success)
98    }
99
100    /// Get style for error messages
101    pub fn error(&self) -> Style {
102        Style::default().fg(self.error).add_modifier(Modifier::BOLD)
103    }
104
105    /// Get style for warning messages
106    pub fn warning(&self) -> Style {
107        Style::default().fg(self.warning)
108    }
109
110    /// Get style for info messages
111    pub fn info(&self) -> Style {
112        Style::default().fg(self.info)
113    }
114
115    /// Get style for progress indicators
116    pub fn progress(&self) -> Style {
117        Style::default().fg(self.progress)
118    }
119
120    /// Get style for borders (normal)
121    pub fn border(&self) -> Style {
122        Style::default().fg(self.border)
123    }
124
125    /// Get style for borders (focused)
126    pub fn border_focused(&self) -> Style {
127        Style::default()
128            .fg(self.border_focused)
129            .add_modifier(Modifier::BOLD)
130    }
131
132    /// Get style for selected items
133    #[allow(dead_code)]
134    pub fn selected(&self) -> Style {
135        Style::default()
136            .bg(self.selection)
137            .add_modifier(Modifier::BOLD)
138    }
139
140    /// Get style for highlighted text
141    pub fn highlight(&self) -> Style {
142        Style::default()
143            .fg(self.primary)
144            .add_modifier(Modifier::BOLD)
145    }
146
147    /// Get style for dimmed/secondary text
148    pub fn dimmed(&self) -> Style {
149        Style::default()
150            .fg(Color::DarkGray)
151            .add_modifier(Modifier::DIM)
152    }
153}