1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct Rgb {
10 pub r: u8,
11 pub g: u8,
12 pub b: u8,
13}
14
15const fn rgb(r: u8, g: u8, b: u8) -> Rgb {
16 Rgb { r, g, b }
17}
18
19pub const BASE: Rgb = rgb(0x16, 0x16, 0x1e);
21pub const TEXT: Rgb = rgb(0xe8, 0xe4, 0xda);
22pub const MUTED: Rgb = rgb(0x6b, 0x6f, 0x7e);
23pub const ACCENT: Rgb = rgb(0xf0, 0xa3, 0x5e);
24pub const PREVIEW_BG: Rgb = rgb(0x4a, 0x33, 0x1c);
26pub const FLASH_BG: Rgb = rgb(0x6b, 0x47, 0x22);
28pub const SELECT_BG: Rgb = rgb(0x2a, 0x2c, 0x3a);
29pub const PAIR_BG: Rgb = rgb(0x3a, 0x3d, 0x4d);
31pub const SECONDARY: Rgb = rgb(0x9b, 0xa0, 0xb1);
33
34pub const DIAG_ERROR: Rgb = rgb(0xe8, 0x67, 0x7a);
36pub const DIAG_INFO: Rgb = rgb(0x7f, 0xb4, 0xca);
37
38pub const CLASS_KEYWORD: Rgb = rgb(0xc5, 0x8a, 0xe8);
40pub const CLASS_FUNCTION: Rgb = DIAG_INFO;
41pub const CLASS_TYPE: Rgb = rgb(0x94, 0xd2, 0xbd);
42pub const CLASS_STRING: Rgb = rgb(0xa9, 0xc4, 0x7c);
43pub const CLASS_NUMBER: Rgb = rgb(0xe8, 0x97, 0x7a);
44pub const CLASS_OPERATOR: Rgb = rgb(0x9a, 0xa0, 0xae);
45pub const CLASS_PUNCTUATION: Rgb = rgb(0x56, 0x5b, 0x6e);
46pub const CLASS_ATTRIBUTE: Rgb = rgb(0xd0, 0xa4, 0x5e);
47
48pub const ANSI16: [Rgb; 16] = [
55 rgb(0x10, 0x10, 0x18), DIAG_ERROR, CLASS_STRING, rgb(0xe0, 0xaf, 0x68), DIAG_INFO, CLASS_KEYWORD, CLASS_TYPE, rgb(0xcf, 0xcb, 0xc0), CLASS_PUNCTUATION, rgb(0xf2, 0x88, 0x96), rgb(0xbc, 0xd7, 0x95), ACCENT, rgb(0x97, 0xc8, 0xdc), rgb(0xd3, 0xa4, 0xee), rgb(0xab, 0xe2, 0xd0), TEXT, ];
72
73const fn cube_level(index: u8) -> u8 {
75 if index == 0 {
76 0
77 } else {
78 55 + 40 * index
79 }
80}
81
82pub const fn ansi256() -> [Rgb; 256] {
86 let mut colors = [rgb(0, 0, 0); 256];
87 let mut index = 0;
88 while index < 16 {
89 colors[index] = ANSI16[index];
90 index += 1;
91 }
92 while index < 232 {
93 let offset = index - 16;
94 colors[index] = rgb(
95 cube_level((offset / 36) as u8),
96 cube_level(((offset % 36) / 6) as u8),
97 cube_level((offset % 6) as u8),
98 );
99 index += 1;
100 }
101 while index < 256 {
102 let level = 8 + 10 * (index - 232) as u8;
103 colors[index] = rgb(level, level, level);
104 index += 1;
105 }
106 colors
107}
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112
113 #[test]
114 fn ansi256_plants_the_seed_and_the_standard_ramps() {
115 let colors = ansi256();
116 assert_eq!(&colors[..16], &ANSI16);
117 assert_eq!(colors[16], rgb(0, 0, 0));
119 assert_eq!(colors[196], rgb(255, 0, 0));
120 assert_eq!(colors[231], rgb(255, 255, 255));
121 assert_eq!(colors[232], rgb(8, 8, 8));
123 assert_eq!(colors[255], rgb(238, 238, 238));
124 }
125}