vtcode_core/ui/
styled.rs

1use super::theme;
2use anstream::println as styled_println;
3use anstyle::{Color, Effects, Reset, Style};
4
5/// Style presets for consistent UI theming
6pub struct Styles;
7
8impl Styles {
9    /// Error message style (red)
10    pub fn error() -> Style {
11        theme::active_styles().error
12    }
13
14    /// Warning message style (yellow)
15    pub fn warning() -> Style {
16        theme::active_styles().secondary
17    }
18
19    /// Success message style (green)
20    pub fn success() -> Style {
21        theme::active_styles().primary
22    }
23
24    /// Info message style (blue)
25    pub fn info() -> Style {
26        theme::active_styles().output
27    }
28
29    /// Debug message style (cyan)
30    pub fn debug() -> Style {
31        theme::active_styles().response
32    }
33
34    /// Bold text style
35    pub fn bold() -> Style {
36        Style::new().effects(Effects::BOLD)
37    }
38
39    /// Bold error style
40    pub fn bold_error() -> Style {
41        theme::active_styles().error.bold()
42    }
43
44    /// Bold success style
45    pub fn bold_success() -> Style {
46        theme::active_styles().primary.bold()
47    }
48
49    /// Bold warning style
50    pub fn bold_warning() -> Style {
51        theme::active_styles().secondary.bold()
52    }
53
54    /// Header style (bold blue)
55    pub fn header() -> Style {
56        let accent = theme::banner_color();
57        Style::new()
58            .fg_color(Some(Color::Rgb(accent)))
59            .effects(Effects::BOLD)
60    }
61
62    /// Code style (magenta)
63    pub fn code() -> Style {
64        theme::active_styles().secondary
65    }
66
67    /// Render style to ANSI string
68    pub fn render(style: &Style) -> String {
69        format!("{}", style)
70    }
71
72    /// Render reset ANSI string
73    pub fn render_reset() -> String {
74        format!("{}", Reset)
75    }
76}
77
78/// Print a styled error message
79pub fn error(message: &str) {
80    styled_println!(
81        "{}{}{}",
82        Styles::render(&Styles::error()),
83        message,
84        Styles::render_reset()
85    );
86}
87
88/// Print a styled warning message
89pub fn warning(message: &str) {
90    styled_println!(
91        "{}{}{}",
92        Styles::render(&Styles::warning()),
93        message,
94        Styles::render_reset()
95    );
96}
97
98/// Print a styled success message
99pub fn success(message: &str) {
100    styled_println!(
101        "{}{}{}",
102        Styles::render(&Styles::success()),
103        message,
104        Styles::render_reset()
105    );
106}
107
108/// Print a styled info message
109pub fn info(message: &str) {
110    styled_println!(
111        "{}{}{}",
112        Styles::render(&Styles::info()),
113        message,
114        Styles::render_reset()
115    );
116}
117
118/// Print a styled debug message
119pub fn debug(message: &str) {
120    styled_println!(
121        "{}{}{}",
122        Styles::render(&Styles::debug()),
123        message,
124        Styles::render_reset()
125    );
126}
127
128/// Print a styled bold message
129pub fn bold(message: &str) {
130    styled_println!(
131        "{}{}{}",
132        Styles::render(&Styles::bold()),
133        message,
134        Styles::render_reset()
135    );
136}
137
138/// Print a styled message with custom style
139pub fn styled(style: &Style, message: &str) {
140    styled_println!(
141        "{}{}{}",
142        Styles::render(style),
143        message,
144        Styles::render_reset()
145    );
146}
147
148#[cfg(test)]
149mod tests {
150    use super::*;
151
152    #[test]
153    fn test_styles() {
154        // These should not panic
155        error("Test error");
156        warning("Test warning");
157        success("Test success");
158        info("Test info");
159        debug("Test debug");
160        bold("Test bold");
161        styled(&Styles::header(), "Test custom");
162    }
163}