1use std::fmt::{self, Display};
2
3pub const BOLD: &str = "\x1b[1m";
4pub const ITALIC: &str = "\x1b[3m";
5pub const UNDERLINE: &str = "\x1b[4m";
6pub const RESET: &str = "\x1b[0m";
7
8pub enum Color {
9 Black,
10 Red,
11 Green,
12 Yellow,
13 Blue,
14 Magenta,
15 Cyan,
16 White,
17}
18
19impl Color {
20 fn sgr_offset(&self) -> u8 {
21 match self {
22 Self::Black => 0,
23 Self::Red => 1,
24 Self::Green => 2,
25 Self::Yellow => 3,
26 Self::Blue => 4,
27 Self::Magenta => 5,
28 Self::Cyan => 6,
29 Self::White => 7,
30 }
31 }
32}
33
34pub struct Fg(pub Color);
35
36impl Display for Fg {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "\x1b[{}m", 30 + self.0.sgr_offset())
39 }
40}
41
42pub struct Bg(pub Color);
43
44impl Display for Bg {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 write!(f, "\x1b[{}m", 40 + self.0.sgr_offset())
47 }
48}