1pub enum Style { ResetAll, Bold, Dim, Italic, Underline, Blink, Inverted, Password, Strike }
2pub enum Color { Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, Default }
3
4impl Color {
5 pub fn fg(clr: Color) -> String {
6 match clr {
7 Color::Black => String::from("\x1b[30m"),
8 Color::Red => String::from("\x1b[31m"),
9 Color::Green => String::from("\x1b[32m"),
10 Color::Yellow => String::from("\x1b[33m"),
11 Color::Blue => String::from("\x1b[34m"),
12 Color::Magenta => String::from("\x1b[35m"),
13 Color::Cyan => String::from("\x1b[36m"),
14 Color::White => String::from("\x1b[37m"),
15 Color::Default => String::from("\x1b[39m"),
16 }
17 }
18
19 pub fn bg(clr: Color) -> String {
20 match clr {
21 Color::Black => String::from("\x1b[40m"),
22 Color::Red => String::from("\x1b[41m"),
23 Color::Green => String::from("\x1b[42m"),
24 Color::Yellow => String::from("\x1b[43m"),
25 Color::Blue => String::from("\x1b[44m"),
26 Color::Magenta => String::from("\x1b[45m"),
27 Color::Cyan => String::from("\x1b[46m"),
28 Color::White => String::from("\x1b[47m"),
29 Color::Default => String::from("\x1b[49m"),
30 }
31 }
32}
33
34impl std::fmt::Display for Style {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 match self {
37 Style::ResetAll => write!(f, "\x1b[0m"),
38 Style::Bold => write!(f, "\x1b[1m"),
39 Style::Dim => write!(f, "\x1b[2m"),
40 Style::Italic => write!(f, "\x1b[3m"),
41 Style::Underline => write!(f, "\x1b[4m"),
42 Style::Blink => write!(f, "\x1b[5m"),
43 Style::Inverted => write!(f, "\x1b[7m"),
44 Style::Password => write!(f, "\x1b[8m"),
45 Style::Strike => write!(f, "\x1b[9m"),
46 }
47 }
48}