1use console::Style;
7use std::fmt;
8
9pub struct UiStyle {
11 pub success: Style,
13 pub warning: Style,
15 pub error: Style,
17 pub info: Style,
19 pub bold: Style,
21}
22
23impl UiStyle {
24 pub fn new() -> Self {
26 Self {
27 success: Style::new().green().bold(),
28 warning: Style::new().yellow().bold(),
29 error: Style::new().red().bold(),
30 info: Style::new().cyan().bold(),
31 bold: Style::new().bold(),
32 }
33 }
34}
35
36impl Default for UiStyle {
37 fn default() -> Self {
38 Self::new()
39 }
40}
41
42impl UiStyle {
43 pub fn action<T: fmt::Display>(&self, label: &str, message: T) {
46 println!("{:>12} {}", self.success.apply_to(label), message);
47 }
48
49 pub fn info<T: fmt::Display>(&self, label: &str, message: T) {
51 println!("{:>12} {}", self.info.apply_to(label), message);
52 }
53
54 pub fn warn<T: fmt::Display>(&self, message: T) {
56 eprintln!("{:>12} {}", self.warning.apply_to("Warning"), message);
57 }
58
59 pub fn error<T: fmt::Display>(&self, message: T) {
61 eprintln!("{:>12} {}", self.error.apply_to("Error"), message);
62 }
63
64 pub fn finished<T: fmt::Display>(&self, message: T) {
66 println!("{:>12} {}", self.success.apply_to("Finished"), message);
67 }
68}
69
70lazy_static::lazy_static! {
71 pub static ref UI: UiStyle = UiStyle::new();
73}