#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
BrightBlack,
BrightRed,
BrightGreen,
BrightYellow,
BrightBlue,
BrightMagenta,
BrightCyan,
BrightWhite,
AnsiColor(u8),
TrueColor {
r: u8,
g: u8,
b: u8,
},
}
impl Color {
pub(crate) fn ansi_fg(self) -> String {
match self {
Self::Black => "\x1b[30m".to_string(),
Self::Red => "\x1b[31m".to_string(),
Self::Green => "\x1b[32m".to_string(),
Self::Yellow => "\x1b[33m".to_string(),
Self::Blue => "\x1b[34m".to_string(),
Self::Magenta => "\x1b[35m".to_string(),
Self::Cyan => "\x1b[36m".to_string(),
Self::White => "\x1b[37m".to_string(),
Self::BrightBlack => "\x1b[90m".to_string(),
Self::BrightRed => "\x1b[91m".to_string(),
Self::BrightGreen => "\x1b[92m".to_string(),
Self::BrightYellow => "\x1b[93m".to_string(),
Self::BrightBlue => "\x1b[94m".to_string(),
Self::BrightMagenta => "\x1b[95m".to_string(),
Self::BrightCyan => "\x1b[96m".to_string(),
Self::BrightWhite => "\x1b[97m".to_string(),
Self::AnsiColor(n) => format!("\x1b[38;5;{n}m"),
Self::TrueColor { r, g, b } => format!("\x1b[38;2;{r};{g};{b}m"),
}
}
pub(crate) fn ansi_bg(self) -> String {
match self {
Self::Black => "\x1b[40m".to_string(),
Self::Red => "\x1b[41m".to_string(),
Self::Green => "\x1b[42m".to_string(),
Self::Yellow => "\x1b[43m".to_string(),
Self::Blue => "\x1b[44m".to_string(),
Self::Magenta => "\x1b[45m".to_string(),
Self::Cyan => "\x1b[46m".to_string(),
Self::White => "\x1b[47m".to_string(),
Self::BrightBlack => "\x1b[100m".to_string(),
Self::BrightRed => "\x1b[101m".to_string(),
Self::BrightGreen => "\x1b[102m".to_string(),
Self::BrightYellow => "\x1b[103m".to_string(),
Self::BrightBlue => "\x1b[104m".to_string(),
Self::BrightMagenta => "\x1b[105m".to_string(),
Self::BrightCyan => "\x1b[106m".to_string(),
Self::BrightWhite => "\x1b[107m".to_string(),
Self::AnsiColor(n) => format!("\x1b[48;5;{n}m"),
Self::TrueColor { r, g, b } => format!("\x1b[48;2;{r};{g};{b}m"),
}
}
}
pub struct CustomColor {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl CustomColor {
pub fn new(r: u8, g: u8, b: u8) -> Self {
Self { r, g, b }
}
}
impl From<(u8, u8, u8)> for CustomColor {
fn from((r, g, b): (u8, u8, u8)) -> Self {
Self { r, g, b }
}
}