const ANSI_RESET: &str = "\x1b[0m";
#[derive(Debug, Clone, Copy)]
pub enum Color {
Red,
Green,
Blue,
Yellow,
Magenta,
Cyan,
White,
}
impl Color {
fn code(&self) -> &str {
match self {
Color::Red => "\x1b[1;31m",
Color::Green => "\x1b[1;32m",
Color::Blue => "\x1b[1;34m",
Color::Yellow => "\x1b[1;33m",
Color::Magenta => "\x1b[1;35m",
Color::Cyan => "\x1b[1;36m",
Color::White => "\x1b[1;37m",
}
}
}
pub fn color_println(color: Color, text: &str) {
println!("{}{}{}", color.code(), text, ANSI_RESET);
}
pub fn color_println_fmt(color: Color, text: &str) -> String {
format!("{}{}{}", color.code(), text, ANSI_RESET)
}