1pub struct ColorFg(AnsiBuilder);
2
3impl ColorFg {
4 ansi_sgr!(black, "30");
5 ansi_sgr!(blue, "34");
6 ansi_sgr!(bright_blue, "94");
7 ansi_sgr!(bright_cyan, "96");
8 ansi_sgr!(bright_green, "92");
9 ansi_sgr!(bright_magenta, "95");
10 ansi_sgr!(bright_red, "91");
11 ansi_sgr!(bright_white, "97");
12 ansi_sgr!(bright_yellow, "93");
13 ansi_sgr!(cyan, "36");
14 ansi_sgr!(gray, "90");
15 ansi_sgr!(green, "32");
16 ansi_sgr!(magenta, "35");
17 ansi_sgr!(red, "31");
18 ansi_sgr!(white, "37");
19 ansi_sgr!(yellow, "33");
20
21 #[inline]
22 pub fn rgb(mut self, r: u8, g: u8, b: u8) -> AnsiBuilder {
23 self.0.0.push_str(&format!("\x1B[38;2;{};{};{}", r, g, b));
24 self.0
25 }
26}
27
28pub struct ColorBg(AnsiBuilder);
29
30impl ColorBg {
31 ansi_sgr!(black, "40");
32 ansi_sgr!(blue, "44");
33 ansi_sgr!(bright_blue, "104");
34 ansi_sgr!(bright_cyan, "106");
35 ansi_sgr!(bright_green, "102");
36 ansi_sgr!(bright_magenta, "105");
37 ansi_sgr!(bright_red, "101");
38 ansi_sgr!(bright_white, "107");
39 ansi_sgr!(bright_yellow, "103");
40 ansi_sgr!(cyan, "46");
41 ansi_sgr!(gray, "100");
42 ansi_sgr!(green, "42");
43 ansi_sgr!(magenta, "45");
44 ansi_sgr!(red, "41");
45 ansi_sgr!(white, "47");
46 ansi_sgr!(yellow, "43");
47
48 #[inline]
49 pub fn rgb(mut self, r: u8, g: u8, b: u8) -> AnsiBuilder {
50 self.0.0.push_str(&format!("\x1B[48;2;{};{};{}", r, g, b));
51 self.0
52 }
53}
54
55pub struct Color(pub AnsiBuilder);
56
57impl Color {
58 pub fn fg(self) -> ColorFg {
59 ColorFg(self.0)
60 }
61
62 pub fn bg(self) -> ColorBg {
63 ColorBg(self.0)
64 }
65}
66
67use crate::AnsiBuilder;