Skip to main content

rab/tui/
theme.rs

1/// Theme trait for components that need color styling.
2///
3/// Implementations provide foreground and background color functions
4/// that take text and return ANSI-styled strings.
5pub trait Theme {
6    /// Apply a foreground color to text.
7    /// `color` is a color name (e.g., "accent", "text", "success", "error", "muted").
8    fn fg(&self, color: &str, text: &str) -> String;
9
10    /// Apply a background color to text.
11    fn bg(&self, color: &str, text: &str) -> String;
12
13    /// Apply bold styling.
14    fn bold(&self, text: &str) -> String;
15
16    /// Apply italic styling (used for thinking blocks, matching pi).
17    fn italic(&self, text: &str) -> String;
18}
19
20/// A no-op theme that returns text unchanged.
21/// Useful for testing components without needing a real theme.
22#[derive(Debug, Clone, Copy, Default)]
23pub struct NoopTheme;
24
25impl Theme for NoopTheme {
26    fn fg(&self, _color: &str, text: &str) -> String {
27        text.to_string()
28    }
29
30    fn bg(&self, _color: &str, text: &str) -> String {
31        text.to_string()
32    }
33
34    fn bold(&self, text: &str) -> String {
35        text.to_string()
36    }
37
38    fn italic(&self, text: &str) -> String {
39        text.to_string()
40    }
41}