vtcode_core/ui/
styled.rs

1use super::theme;
2use anstream::println as styled_println;
3use anstyle::{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        theme::active_styles().response
57    }
58
59    /// Code style (magenta)
60    pub fn code() -> Style {
61        theme::active_styles().secondary
62    }
63
64    /// Render style to ANSI string
65    pub fn render(style: &Style) -> String {
66        format!("{}", style)
67    }
68
69    /// Render reset ANSI string
70    pub fn render_reset() -> String {
71        format!("{}", Reset)
72    }
73}
74
75/// Print a styled error message
76pub fn error(message: &str) {
77    styled_println!(
78        "{}{}{}",
79        Styles::render(&Styles::error()),
80        message,
81        Styles::render_reset()
82    );
83}
84
85/// Print a styled warning message
86pub fn warning(message: &str) {
87    styled_println!(
88        "{}{}{}",
89        Styles::render(&Styles::warning()),
90        message,
91        Styles::render_reset()
92    );
93}
94
95/// Print a styled success message
96pub fn success(message: &str) {
97    styled_println!(
98        "{}{}{}",
99        Styles::render(&Styles::success()),
100        message,
101        Styles::render_reset()
102    );
103}
104
105/// Print a styled info message
106pub fn info(message: &str) {
107    styled_println!(
108        "{}{}{}",
109        Styles::render(&Styles::info()),
110        message,
111        Styles::render_reset()
112    );
113}
114
115/// Print a styled debug message
116pub fn debug(message: &str) {
117    styled_println!(
118        "{}{}{}",
119        Styles::render(&Styles::debug()),
120        message,
121        Styles::render_reset()
122    );
123}
124
125/// Print a styled bold message
126pub fn bold(message: &str) {
127    styled_println!(
128        "{}{}{}",
129        Styles::render(&Styles::bold()),
130        message,
131        Styles::render_reset()
132    );
133}
134
135/// Print a styled message with custom style
136pub fn styled(style: &Style, message: &str) {
137    styled_println!(
138        "{}{}{}",
139        Styles::render(style),
140        message,
141        Styles::render_reset()
142    );
143}
144
145#[cfg(test)]
146mod tests {
147    use super::*;
148
149    #[test]
150    fn test_styles() {
151        // These should not panic
152        error("Test error");
153        warning("Test warning");
154        success("Test success");
155        info("Test info");
156        debug("Test debug");
157        bold("Test bold");
158        styled(&Styles::header(), "Test custom");
159    }
160}