#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Effect {
Bold,
Dimmed,
Italic,
Underline,
Blink,
BlinkFast,
Reversed,
Hidden,
Strikethrough,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum AnsiColor {
Black,
BrightBlack,
Red,
BrightRed,
Green,
BrightGreen,
Yellow,
BrightYellow,
Blue,
BrightBlue,
Magenta,
BrightMagenta,
Cyan,
BrightCyan,
White,
BrightWhite,
}
impl Into<Color> for AnsiColor {
fn into(self) -> Color {
Color::Ansi(self)
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Color {
Custom {
r: u8,
g: u8,
b: u8,
},
Ansi(AnsiColor),
}
impl Color {
pub fn rgb(r: u8, g: u8, b: u8) -> Self {
Self::Custom {
r,
g,
b,
}
}
pub fn ansi(color: AnsiColor) -> Self {
Self::Ansi(color)
}
}
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Style {
pub fg: Option<Color>,
pub bg: Option<Color>,
pub effects: Vec<Effect>,
}
impl Style {
pub fn new() -> Self {
Self {
fg: None,
bg: None,
effects: Vec::new(),
}
}
pub fn fg(mut self, color: Option<impl Into<Color>>) -> Self {
self.fg = match color {
Some(s) => Some(s.into()),
None => None,
};
return self;
}
pub fn bg(mut self, color: Option<impl Into<Color>>) -> Self {
self.bg = match color {
Some(s) => Some(s.into()),
None => None,
};
return self;
}
pub fn effect(mut self, effect: Effect) -> Self {
self.effects.push(effect);
return self;
}
pub fn effects(mut self, effects: &[Effect]) -> Self {
for i in effects {
self.effects.push(*i);
}
return self;
}
}