use colored::{Color, ColoredString, Colorize};
pub fn hex_to_color(hex: &str) -> Color {
let hex = hex.trim_start_matches('#');
if hex.len() == 6 {
if let (Ok(r), Ok(g), Ok(b)) = (
u8::from_str_radix(&hex[0..2], 16),
u8::from_str_radix(&hex[2..4], 16),
u8::from_str_radix(&hex[4..6], 16),
) {
return Color::TrueColor { r, g, b };
}
}
Color::White
}
pub fn hex_color<S: AsRef<str>>(text: S, hex: &str) -> ColoredString {
text.as_ref().color(hex_to_color(hex))
}
pub fn bold_hex<S: AsRef<str>>(text: S, hex: &str) -> ColoredString {
text.as_ref().color(hex_to_color(hex)).bold()
}
#[allow(dead_code)]
pub fn bright_hex<S: AsRef<str>>(text: S, hex: &str) -> ColoredString {
text.as_ref().color(hex_to_color(hex)).underline()
}