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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use tui::style::Color;
#[derive(Debug, PartialEq)]
#[repr(u8)]
pub enum AnsiCode {
Reset,
Bold,
Faint,
Italic,
Underline,
SlowBlink,
RapidBlink,
Reverse,
Conceal,
CrossedOut,
PrimaryFont,
AlternateFont,
AlternateFonts(u8),
Fraktur,
BoldOff,
Normal,
NotItalic,
UnderlineOff,
BlinkOff,
InvertOff,
Reveal,
CrossedOutOff,
ForegroundColor(Color),
SetForegroundColor,
DefaultForegroundColor,
BackgroundColor(Color),
SetBackgroundColor,
DefaultBackgroundColor,
}
impl From<u8> for AnsiCode {
fn from(code: u8) -> Self {
match code {
0 => AnsiCode::Reset,
1 => AnsiCode::Bold,
2 => AnsiCode::Faint,
3 => AnsiCode::Italic,
4 => AnsiCode::Underline,
5 => AnsiCode::SlowBlink,
6 => AnsiCode::RapidBlink,
7 => AnsiCode::Reverse,
8 => AnsiCode::Conceal,
9 => AnsiCode::CrossedOut,
10 => AnsiCode::PrimaryFont,
11 => AnsiCode::AlternateFont,
20 => AnsiCode::Fraktur,
21 => AnsiCode::BoldOff,
22 => AnsiCode::Normal,
23 => AnsiCode::NotItalic,
24 => AnsiCode::UnderlineOff,
25 => AnsiCode::BlinkOff,
27 => AnsiCode::InvertOff,
28 => AnsiCode::Reveal,
29 => AnsiCode::CrossedOutOff,
30 => AnsiCode::ForegroundColor(Color::Black),
31 => AnsiCode::ForegroundColor(Color::Red),
32 => AnsiCode::ForegroundColor(Color::Green),
33 => AnsiCode::ForegroundColor(Color::Yellow),
34 => AnsiCode::ForegroundColor(Color::Blue),
35 => AnsiCode::ForegroundColor(Color::Magenta),
36 => AnsiCode::ForegroundColor(Color::Cyan),
37 => AnsiCode::ForegroundColor(Color::Gray),
38 => AnsiCode::SetForegroundColor,
39 => AnsiCode::DefaultForegroundColor,
40 => AnsiCode::BackgroundColor(Color::Black),
41 => AnsiCode::BackgroundColor(Color::Red),
42 => AnsiCode::BackgroundColor(Color::Green),
43 => AnsiCode::BackgroundColor(Color::Yellow),
44 => AnsiCode::BackgroundColor(Color::Blue),
45 => AnsiCode::BackgroundColor(Color::Magenta),
46 => AnsiCode::BackgroundColor(Color::Cyan),
47 => AnsiCode::BackgroundColor(Color::Gray),
48 => AnsiCode::SetBackgroundColor,
49 => AnsiCode::DefaultBackgroundColor,
_ => AnsiCode::Reset,
}
}
}