1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fmt;
#[derive(Copy, Clone, Debug)]
#[allow(dead_code)]
pub enum Colors {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
BrightBlack,
BrightRed,
BrightGreen,
BrightYellow,
BrightBlue,
BrightMagenta,
BrightCyan,
Reset,
}
impl fmt::Display for Colors {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let code = match *self as u8 {
0..=7 => format!("\x1b[3{}m", *self as u8),
8..=14 => format!("\x1b[9{}m", *self as u8),
15 => "\x1b[0m".to_string(),
_ => panic!("forgot to add a new case for match"),
};
write!(f, "{}", code)
}
}