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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
pub mod ansi_to_html;
pub fn print_color(s: usize, log: &mut Vec<u8>) {
assert!(s < 7);
if s == 0 {
log.append(&mut b"[01m[38;5;75m".to_vec());
} else if s == 1 {
log.append(&mut b"[01m[38;5;166m".to_vec());
} else if s == 2 {
log.append(&mut b"[38;5;178m".to_vec());
} else if s == 3 {
log.append(&mut b"[01m[38;5;25m".to_vec());
} else if s == 4 {
log.append(&mut b"[01m[38;5;175m".to_vec());
} else if s == 5 {
log.append(&mut b"[38;5;36m".to_vec());
} else {
log.append(&mut b"[01m[38;5;11m".to_vec());
}
}
pub fn best_color_order(i: usize) -> usize {
if i == 0 {
3
} else if i == 1 {
4
} else if i == 2 {
5
} else if i == 3 {
1
} else if i == 4 {
0
} else if i == 5 {
2
} else {
6
}
}
pub fn ansi_256(n: usize) -> Vec<u8> {
let mut x = b"[38;5;".to_vec();
x.append(&mut format!("{}", n).as_bytes().to_vec());
x.push(b'm');
x
}
pub fn print_color13_ansi(s: usize, log: &mut Vec<u8>) {
assert!(s < 13);
if s == 0 {
log.append(&mut ansi_256(0));
} else if s == 1 {
log.append(&mut ansi_256(23));
} else if s == 2 {
log.append(&mut ansi_256(53));
} else if s == 3 {
log.append(&mut ansi_256(20));
} else if s == 4 {
log.append(&mut ansi_256(33));
} else if s == 5 {
log.append(&mut ansi_256(170));
} else if s == 6 {
log.append(&mut ansi_256(6));
} else if s == 7 {
log.append(&mut ansi_256(1));
} else if s == 8 {
log.append(&mut ansi_256(28));
} else if s == 9 {
log.append(&mut ansi_256(209));
} else if s == 10 {
log.append(&mut ansi_256(185));
} else if s == 11 {
log.append(&mut ansi_256(84));
} else if s == 12 {
log.append(&mut ansi_256(223));
}
}
pub fn print_color13(s: usize) -> (usize, usize, usize) {
assert!(s < 13);
if s == 0 {
(0, 0, 0)
} else if s == 1 {
(0, 110, 130)
} else if s == 2 {
(130, 20, 160)
} else if s == 3 {
(0, 90, 200)
} else if s == 4 {
(0, 160, 250)
} else if s == 5 {
(250, 120, 250)
} else if s == 6 {
(20, 210, 220)
} else if s == 7 {
(170, 10, 60)
} else if s == 8 {
(10, 155, 75)
} else if s == 9 {
(255, 130, 95)
} else if s == 10 {
(234, 214, 68)
} else if s == 11 {
(160, 250, 130)
} else {
(250, 230, 190)
}
}
pub fn emit_red_escape(log: &mut Vec<u8>) {
log.append(&mut b"[31m".to_vec());
}
pub fn emit_blue_escape(log: &mut Vec<u8>) {
log.append(&mut b"[38;5;12m".to_vec());
}
pub fn emit_green_escape(log: &mut Vec<u8>) {
log.append(&mut b"[32m".to_vec());
}
pub fn emit_bold_escape(log: &mut Vec<u8>) {
log.append(&mut b"[01m".to_vec());
}
pub fn emit_end_escape(log: &mut Vec<u8>) {
log.append(&mut b"[0m".to_vec());
}
pub fn bold(s: &str) -> String {
format!("[01m{}[0m", s)
}
pub fn emit_eight_bit_color_escape(log: &mut Vec<u8>, c: usize) {
log.append(&mut b"[38;5;".to_vec());
log.append(&mut format!("{}", c).as_bytes().to_vec());
log.push(b'm');
}
pub fn emit_disable_alternate_screen_buffer_escape(log: &mut Vec<u8>) {
log.append(&mut b"[?1049l".to_vec());
}