use regex::Regex;
pub fn hex_to_rgb(hex: &str) -> (u8, u8, u8) {
let f = hex.trim_start_matches("[$#").trim_end_matches("]").to_string();
let r = u8::from_str_radix(&f[0..2], 16);
let g = u8::from_str_radix(&f[2..4], 16);
let b = u8::from_str_radix(&f[4..6], 16);
if r.is_err() || g.is_err() || b.is_err() {
panic!("Invalid color hex string: {}", hex);
}
(r.unwrap(), g.unwrap(), b.unwrap())
}
pub trait NoAnsi {
fn no_ansi(&self) -> String;
}
impl NoAnsi for str {
fn no_ansi(&self) -> String {
let re = Regex::new(r"(?:\x1b\[[;\d]*m)").unwrap();
re.replace_all(&self, "").to_string()
}
}