use ratatui::style::{Color as RColor, Style};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
Indexed(u8),
Rgb(u8, u8, u8),
#[default]
Default,
}
impl Color {
pub fn to_ratatui(&self) -> RColor {
match self {
Color::Black => RColor::Black,
Color::Red => RColor::Red,
Color::Green => RColor::Green,
Color::Yellow => RColor::Yellow,
Color::Blue => RColor::Blue,
Color::Magenta => RColor::Magenta,
Color::Cyan => RColor::Cyan,
Color::White => RColor::White,
Color::Indexed(n) => RColor::Indexed(*n),
Color::Rgb(r, g, b) => RColor::Rgb(*r, *g, *b),
Color::Default => RColor::Reset,
}
}
pub fn to_style(&self, bg: Option<Color>) -> Style {
let fg = self.to_ratatui();
match bg {
Some(bg_color) => Style::new().fg(fg).bg(bg_color.to_ratatui()),
None => Style::new().fg(fg),
}
}
}