use super::rgb::rgb_to_ansi8;
pub fn hex_to_rgb(hex: &str) -> [u8; 3] {
let hex = hex.trim_start_matches('#');
if hex.len() == 6 {
let r = u8::from_str_radix(&hex[0..2], 16).unwrap();
let g = u8::from_str_radix(&hex[2..4], 16).unwrap();
let b = u8::from_str_radix(&hex[4..6], 16).unwrap();
[r, g, b]
} else {
let r = u8::from_str_radix(&hex[0..1].repeat(2), 16).unwrap();
let g = u8::from_str_radix(&hex[1..2].repeat(2), 16).unwrap();
let b = u8::from_str_radix(&hex[2..3].repeat(2), 16).unwrap();
[r, g, b]
}
}
pub fn hex_to_ansi8(hex: &str) -> u8 {
let rgb = hex_to_rgb(hex);
rgb_to_ansi8(rgb)
}