1use colored::{ColoredString, Colorize};
18
19pub struct Status;
21
22impl Status {
23 pub fn ok() -> ColoredString {
25 "[OK]".green()
26 }
27
28 pub fn info() -> ColoredString {
30 "[i]".cyan()
31 }
32
33 pub fn warn() -> ColoredString {
35 "[!]".yellow()
36 }
37
38 pub fn error() -> ColoredString {
40 "[X]".red()
41 }
42
43 pub fn fetch() -> ColoredString {
45 "[<]".blue()
46 }
47
48 pub fn action() -> ColoredString {
50 "[>]".yellow()
51 }
52
53 pub fn index() -> ColoredString {
55 "[#]".blue()
56 }
57
58 pub fn detail() -> ColoredString {
60 "[*]".blue()
61 }
62
63 pub fn summary() -> ColoredString {
65 "[=]".blue()
66 }
67
68 pub fn detect() -> ColoredString {
70 "[D]".blue().bold()
71 }
72
73 pub fn add() -> ColoredString {
75 "[+]".green().bold()
76 }
77
78 pub fn package() -> ColoredString {
80 "[P]".blue()
81 }
82}
83
84pub trait StyledText {
86 fn header(&self) -> ColoredString;
88 fn path(&self) -> ColoredString;
90 fn hash(&self) -> ColoredString;
92 fn count(&self) -> ColoredString;
94 fn success(&self) -> ColoredString;
96 fn separator(&self) -> ColoredString;
98 fn err(&self) -> ColoredString;
100 fn warning(&self) -> ColoredString;
102 fn brand(&self) -> ColoredString;
104}
105
106impl StyledText for str {
107 fn header(&self) -> ColoredString {
108 self.magenta().bold()
109 }
110
111 fn path(&self) -> ColoredString {
112 self.cyan()
113 }
114
115 fn hash(&self) -> ColoredString {
116 self.cyan()
117 }
118
119 fn count(&self) -> ColoredString {
120 self.yellow()
121 }
122
123 fn success(&self) -> ColoredString {
124 self.green()
125 }
126
127 fn separator(&self) -> ColoredString {
128 self.dimmed()
129 }
130
131 fn err(&self) -> ColoredString {
132 self.red()
133 }
134
135 fn warning(&self) -> ColoredString {
136 self.yellow()
137 }
138
139 fn brand(&self) -> ColoredString {
140 self.cyan().bold()
141 }
142}
143
144impl StyledText for String {
145 fn header(&self) -> ColoredString {
146 self.as_str().magenta().bold()
147 }
148
149 fn path(&self) -> ColoredString {
150 self.as_str().cyan()
151 }
152
153 fn hash(&self) -> ColoredString {
154 self.as_str().cyan()
155 }
156
157 fn count(&self) -> ColoredString {
158 self.as_str().yellow()
159 }
160
161 fn success(&self) -> ColoredString {
162 self.as_str().green()
163 }
164
165 fn separator(&self) -> ColoredString {
166 self.as_str().dimmed()
167 }
168
169 fn err(&self) -> ColoredString {
170 self.as_str().red()
171 }
172
173 fn warning(&self) -> ColoredString {
174 self.as_str().yellow()
175 }
176
177 fn brand(&self) -> ColoredString {
178 self.as_str().cyan().bold()
179 }
180}
181
182pub fn separator(width: usize) -> ColoredString {
184 "═".repeat(width).dimmed()
185}
186
187pub fn line(width: usize) -> ColoredString {
189 "=".repeat(width).dimmed()
190}
191
192#[cfg(test)]
193mod tests {
194 use super::*;
195
196 #[test]
197 fn test_status_indicators() {
198 let _ = Status::ok();
200 let _ = Status::info();
201 let _ = Status::warn();
202 let _ = Status::error();
203 let _ = Status::fetch();
204 }
205
206 #[test]
207 fn test_styled_text() {
208 let text = "test";
209 let _ = text.header();
210 let _ = text.path();
211 let _ = text.hash();
212 let _ = text.count();
213 let _ = text.success();
214 }
215}