1use super::theme;
2use anstream::println as styled_println;
3use anstyle::{Effects, Reset, Style};
4
5pub struct Styles;
7
8impl Styles {
9 pub fn error() -> Style {
11 theme::active_styles().error
12 }
13
14 pub fn warning() -> Style {
16 theme::active_styles().secondary
17 }
18
19 pub fn success() -> Style {
21 theme::active_styles().primary
22 }
23
24 pub fn info() -> Style {
26 theme::active_styles().output
27 }
28
29 pub fn debug() -> Style {
31 theme::active_styles().response
32 }
33
34 pub fn bold() -> Style {
36 Style::new().effects(Effects::BOLD)
37 }
38
39 pub fn bold_error() -> Style {
41 theme::active_styles().error.bold()
42 }
43
44 pub fn bold_success() -> Style {
46 theme::active_styles().primary.bold()
47 }
48
49 pub fn bold_warning() -> Style {
51 theme::active_styles().secondary.bold()
52 }
53
54 pub fn header() -> Style {
56 theme::active_styles().response
57 }
58
59 pub fn code() -> Style {
61 theme::active_styles().secondary
62 }
63
64 pub fn render(style: &Style) -> String {
66 format!("{}", style)
67 }
68
69 pub fn render_reset() -> String {
71 format!("{}", Reset)
72 }
73}
74
75pub fn error(message: &str) {
77 styled_println!(
78 "{}{}{}",
79 Styles::render(&Styles::error()),
80 message,
81 Styles::render_reset()
82 );
83}
84
85pub fn warning(message: &str) {
87 styled_println!(
88 "{}{}{}",
89 Styles::render(&Styles::warning()),
90 message,
91 Styles::render_reset()
92 );
93}
94
95pub fn success(message: &str) {
97 styled_println!(
98 "{}{}{}",
99 Styles::render(&Styles::success()),
100 message,
101 Styles::render_reset()
102 );
103}
104
105pub fn info(message: &str) {
107 styled_println!(
108 "{}{}{}",
109 Styles::render(&Styles::info()),
110 message,
111 Styles::render_reset()
112 );
113}
114
115pub fn debug(message: &str) {
117 styled_println!(
118 "{}{}{}",
119 Styles::render(&Styles::debug()),
120 message,
121 Styles::render_reset()
122 );
123}
124
125pub fn bold(message: &str) {
127 styled_println!(
128 "{}{}{}",
129 Styles::render(&Styles::bold()),
130 message,
131 Styles::render_reset()
132 );
133}
134
135pub 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 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}