#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Rgb {
pub r: u8,
pub g: u8,
pub b: u8,
}
const fn rgb(r: u8, g: u8, b: u8) -> Rgb {
Rgb { r, g, b }
}
pub const BASE: Rgb = rgb(0x16, 0x16, 0x1e);
pub const TEXT: Rgb = rgb(0xe8, 0xe4, 0xda);
pub const MUTED: Rgb = rgb(0x6b, 0x6f, 0x7e);
pub const ACCENT: Rgb = rgb(0xf0, 0xa3, 0x5e);
pub const PREVIEW_BG: Rgb = rgb(0x4a, 0x33, 0x1c);
pub const FLASH_BG: Rgb = rgb(0x6b, 0x47, 0x22);
pub const SELECT_BG: Rgb = rgb(0x2a, 0x2c, 0x3a);
pub const PAIR_BG: Rgb = rgb(0x3a, 0x3d, 0x4d);
pub const SECONDARY: Rgb = rgb(0x9b, 0xa0, 0xb1);
pub const DIAG_ERROR: Rgb = rgb(0xe8, 0x67, 0x7a);
pub const DIAG_INFO: Rgb = rgb(0x7f, 0xb4, 0xca);
pub const CLASS_KEYWORD: Rgb = rgb(0xc5, 0x8a, 0xe8);
pub const CLASS_FUNCTION: Rgb = DIAG_INFO;
pub const CLASS_TYPE: Rgb = rgb(0x94, 0xd2, 0xbd);
pub const CLASS_STRING: Rgb = rgb(0xa9, 0xc4, 0x7c);
pub const CLASS_NUMBER: Rgb = rgb(0xe8, 0x97, 0x7a);
pub const CLASS_OPERATOR: Rgb = rgb(0x9a, 0xa0, 0xae);
pub const CLASS_PUNCTUATION: Rgb = rgb(0x56, 0x5b, 0x6e);
pub const CLASS_ATTRIBUTE: Rgb = rgb(0xd0, 0xa4, 0x5e);
pub const ANSI16: [Rgb; 16] = [
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, ];
const fn cube_level(index: u8) -> u8 {
if index == 0 {
0
} else {
55 + 40 * index
}
}
pub const fn ansi256() -> [Rgb; 256] {
let mut colors = [rgb(0, 0, 0); 256];
let mut index = 0;
while index < 16 {
colors[index] = ANSI16[index];
index += 1;
}
while index < 232 {
let offset = index - 16;
colors[index] = rgb(
cube_level((offset / 36) as u8),
cube_level(((offset % 36) / 6) as u8),
cube_level((offset % 6) as u8),
);
index += 1;
}
while index < 256 {
let level = 8 + 10 * (index - 232) as u8;
colors[index] = rgb(level, level, level);
index += 1;
}
colors
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ansi256_plants_the_seed_and_the_standard_ramps() {
let colors = ansi256();
assert_eq!(&colors[..16], &ANSI16);
assert_eq!(colors[16], rgb(0, 0, 0));
assert_eq!(colors[196], rgb(255, 0, 0));
assert_eq!(colors[231], rgb(255, 255, 255));
assert_eq!(colors[232], rgb(8, 8, 8));
assert_eq!(colors[255], rgb(238, 238, 238));
}
}