prettylog_rs/types/
ansi.rs

1#[derive(Clone, Debug)]
2pub enum AnsiColor {
3    Reset,
4    Bold,
5    Black,
6    Red,
7    Green,
8    Yellow,
9    Blue,
10    Purple,
11    Cyan,
12    White,
13    BrightBlack,
14    BrightRed,
15    BrightGreen,
16    BrightYellow,
17    BrightBlue,
18    BrightPurple,
19    BrightCyan,
20    BrightWhite,
21    BlackBackground,
22    RedBackground,
23    GreenBackground,
24    YellowBackground,
25    BlueBackground,
26    PurpleBackground,
27    CyanBackground,
28    WhiteBackground,
29    BrightBlackBackground,
30    BrightRedBackground,
31    BrightGreenBackground,
32    BrightYellowBackground,
33    BrightBlueBackground,
34    BrightPurpleBackground,
35    BrightCyanBackground,
36    BrightWhiteBackground,
37    Gray,
38    GrayBackground,
39    Orange,
40    OrangeBackground,
41    Pink,
42    PinkBackground,
43    CutePink,
44    CutePinkBackground,
45    Aqua,
46    AquaBackground,
47    Gold,
48    GoldBackground,
49    LightGreen,
50    LightGreenBackground,
51    LightBlue,
52    LightBlueBackground,
53    Magenta,
54    MagentaBackground,
55    LightCyan,
56    LightCyanBackground,
57    LightGray,
58    LightGrayBackground,
59    DarkRed,
60    DarkRedBackground,
61    DarkGreen,
62    DarkGreenBackground,
63    DarkBlue,
64    DarkBlueBackground,
65    DarkYellow,
66    DarkYellowBackground,
67    DarkPurple,
68    DarkPurpleBackground,
69}
70
71impl AnsiColor {
72    pub fn code(&self) -> &str {
73        match self {
74            AnsiColor::Reset => "\u{001B}[0m",
75            AnsiColor::Bold => "\u{001B}[1m",
76            AnsiColor::Black => "\u{001B}[30m",
77            AnsiColor::Red => "\u{001B}[31m",
78            AnsiColor::Green => "\u{001B}[32m",
79            AnsiColor::Yellow => "\u{001B}[33m",
80            AnsiColor::Blue => "\u{001B}[34m",
81            AnsiColor::Purple => "\u{001B}[35m",
82            AnsiColor::Cyan => "\u{001B}[36m",
83            AnsiColor::White => "\u{001B}[37m",
84            AnsiColor::BrightBlack => "\u{001B}[90m",
85            AnsiColor::BrightRed => "\u{001B}[91m",
86            AnsiColor::BrightGreen => "\u{001B}[92m",
87            AnsiColor::BrightYellow => "\u{001B}[93m",
88            AnsiColor::BrightBlue => "\u{001B}[94m",
89            AnsiColor::BrightPurple => "\u{001B}[95m",
90            AnsiColor::BrightCyan => "\u{001B}[96m",
91            AnsiColor::BrightWhite => "\u{001B}[97m",
92            AnsiColor::BlackBackground => "\u{001B}[40m",
93            AnsiColor::RedBackground => "\u{001B}[41m",
94            AnsiColor::GreenBackground => "\u{001B}[42m",
95            AnsiColor::YellowBackground => "\u{001B}[43m",
96            AnsiColor::BlueBackground => "\u{001B}[44m",
97            AnsiColor::PurpleBackground => "\u{001B}[45m",
98            AnsiColor::CyanBackground => "\u{001B}[46m",
99            AnsiColor::WhiteBackground => "\u{001B}[47m",
100            AnsiColor::BrightBlackBackground => "\u{001B}[100m",
101            AnsiColor::BrightRedBackground => "\u{001B}[101m",
102            AnsiColor::BrightGreenBackground => "\u{001B}[102m",
103            AnsiColor::BrightYellowBackground => "\u{001B}[103m",
104            AnsiColor::BrightBlueBackground => "\u{001B}[104m",
105            AnsiColor::BrightPurpleBackground => "\u{001B}[105m",
106            AnsiColor::BrightCyanBackground => "\u{001B}[106m",
107            AnsiColor::BrightWhiteBackground => "\u{001B}[107m",
108            AnsiColor::Gray => "\u{001B}[38;5;244m",
109            AnsiColor::GrayBackground => "\u{001B}[48;5;244m",
110            AnsiColor::Orange => "\u{001B}[38;5;202m",
111            AnsiColor::OrangeBackground => "\u{001B}[48;5;202m",
112            AnsiColor::Pink => "\u{001B}[38;5;200m",
113            AnsiColor::PinkBackground => "\u{001B}[48;5;200m",
114            AnsiColor::CutePink => "\u{001B}[38;5;205m",
115            AnsiColor::CutePinkBackground => "\u{001B}[48;5;205m",
116            AnsiColor::Aqua => "\u{001B}[38;5;45m",
117            AnsiColor::AquaBackground => "\u{001B}[48;5;45m",
118            AnsiColor::Gold => "\u{001B}[38;5;220m",
119            AnsiColor::GoldBackground => "\u{001B}[48;5;220m",
120            AnsiColor::LightGreen => "\u{001B}[38;5;82m",
121            AnsiColor::LightGreenBackground => "\u{001B}[48;5;82m",
122            AnsiColor::LightBlue => "\u{001B}[38;5;39m",
123            AnsiColor::LightBlueBackground => "\u{001B}[48;5;39m",
124            AnsiColor::Magenta => "\u{001B}[38;5;13m",
125            AnsiColor::MagentaBackground => "\u{001B}[48;5;13m",
126            AnsiColor::LightCyan => "\u{001B}[38;5;51m",
127            AnsiColor::LightCyanBackground => "\u{001B}[48;5;51m",
128            AnsiColor::LightGray => "\u{001B}[38;5;247m",
129            AnsiColor::LightGrayBackground => "\u{001B}[48;5;247m",
130            AnsiColor::DarkRed => "\u{001B}[38;5;88m",
131            AnsiColor::DarkRedBackground => "\u{001B}[48;5;88m",
132            AnsiColor::DarkGreen => "\u{001B}[38;5;22m",
133            AnsiColor::DarkGreenBackground => "\u{001B}[48;5;22m",
134            AnsiColor::DarkBlue => "\u{001B}[38;5;19m",
135            AnsiColor::DarkBlueBackground => "\u{001B}[48;5;19m",
136            AnsiColor::DarkYellow => "\u{001B}[38;5;136m",
137            AnsiColor::DarkYellowBackground => "\u{001B}[48;5;136m",
138            AnsiColor::DarkPurple => "\u{001B}[38;5;55m",
139            AnsiColor::DarkPurpleBackground => "\u{001B}[48;5;55m",
140        }
141    }
142}
143
144#[derive(Clone, Debug)]
145pub struct AnsiPair {
146    pub background: AnsiColor,
147    pub foreground: AnsiColor,
148}
149
150impl AnsiPair {
151    pub fn new(background: AnsiColor, foreground: AnsiColor) -> Self {
152        AnsiPair {
153            background,
154            foreground,
155        }
156    }
157}