use std::fmt;
use super::{Paint, Style};
#[derive(Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)]
pub enum Color {
#[default]
Unset,
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
Fixed(u8),
RGB(u8, u8, u8),
}
impl Color {
#[inline]
pub fn paint<T>(self, item: T) -> Paint<T> {
Paint::new(item).fg(self)
}
#[inline]
pub const fn style(self) -> Style {
Style::new(self)
}
pub(crate) fn ansi_fmt(&self, f: &mut dyn fmt::Write) -> fmt::Result {
match *self {
Color::Unset => Ok(()),
Color::Black => write!(f, "0"),
Color::Red => write!(f, "1"),
Color::Green => write!(f, "2"),
Color::Yellow => write!(f, "3"),
Color::Blue => write!(f, "4"),
Color::Magenta => write!(f, "5"),
Color::Cyan => write!(f, "6"),
Color::White => write!(f, "7"),
Color::Fixed(num) => write!(f, "8;5;{num}"),
Color::RGB(r, g, b) => write!(f, "8;2;{r};{g};{b}"),
}
}
}