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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::fmt;
pub enum BackgroundColor {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
EightBit(u8),
RGB(u8, u8, u8),
Normal,
}
impl fmt::Display for BackgroundColor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self{
BackgroundColor::Black => write!(f, "\x1b[40m"),
BackgroundColor::Red => write!(f, "\x1b[41m"),
BackgroundColor::Green => write!(f, "\x1b[42m"),
BackgroundColor::Yellow => write!(f, "\x1b[43m"),
BackgroundColor::Blue => write!(f, "\x1b[44m"),
BackgroundColor::Magenta => write!(f, "\x1b[45m"),
BackgroundColor::Cyan => write!(f, "\x1b[46m"),
BackgroundColor::White => write!(f, "\x1b[47m"),
BackgroundColor::EightBit(c) => write!(f, "\x1b[48;5;{}m", c),
BackgroundColor::RGB(r, g, b) => write!(f, "\x1b[48;2;{};{};{}m", r, g, b),
BackgroundColor::Normal => write!(f, "\x1b[49m"),
}
}
}