#[derive(PartialEq, Clone, Copy)]
pub struct Style {
pub foreground: Option<Colour>,
pub background: Option<Colour>,
pub is_bold: bool,
pub is_dimmed: bool,
pub is_italic: bool,
pub is_underline: bool,
pub is_blink: bool,
pub is_reverse: bool,
pub is_hidden: bool,
pub is_strikethrough: bool
}
impl Style {
pub fn new() -> Style {
Style::default()
}
pub fn bold(&self) -> Style {
Style { is_bold: true, .. *self }
}
pub fn dimmed(&self) -> Style {
Style { is_dimmed: true, .. *self }
}
pub fn italic(&self) -> Style {
Style { is_italic: true, .. *self }
}
pub fn underline(&self) -> Style {
Style { is_underline: true, .. *self }
}
pub fn blink(&self) -> Style {
Style { is_blink: true, .. *self }
}
pub fn reverse(&self) -> Style {
Style { is_reverse: true, .. *self }
}
pub fn hidden(&self) -> Style {
Style { is_hidden: true, .. *self }
}
pub fn strikethrough(&self) -> Style {
Style { is_strikethrough: true, .. *self }
}
pub fn fg(&self, foreground: Colour) -> Style {
Style { foreground: Some(foreground), .. *self }
}
pub fn on(&self, background: Colour) -> Style {
Style { background: Some(background), .. *self }
}
pub fn is_plain(self) -> bool {
self == Style::default()
}
}
impl Default for Style {
fn default() -> Style {
Style {
foreground: None,
background: None,
is_bold: false,
is_dimmed: false,
is_italic: false,
is_underline: false,
is_blink: false,
is_reverse: false,
is_hidden: false,
is_strikethrough: false,
}
}
}
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Colour {
Black,
Red,
Green,
Yellow,
Blue,
Purple,
Cyan,
White,
Fixed(u8),
RGB(u8, u8, u8),
}
impl Colour {
pub fn normal(self) -> Style {
Style { foreground: Some(self), .. Style::default() }
}
pub fn bold(self) -> Style {
Style { foreground: Some(self), is_bold: true, .. Style::default() }
}
pub fn dimmed(self) -> Style {
Style { foreground: Some(self), is_dimmed: true, .. Style::default() }
}
pub fn italic(self) -> Style {
Style { foreground: Some(self), is_italic: true, .. Style::default() }
}
pub fn underline(self) -> Style {
Style { foreground: Some(self), is_underline: true, .. Style::default() }
}
pub fn blink(self) -> Style {
Style { foreground: Some(self), is_blink: true, .. Style::default() }
}
pub fn reverse(self) -> Style {
Style { foreground: Some(self), is_reverse: true, .. Style::default() }
}
pub fn hidden(self) -> Style {
Style { foreground: Some(self), is_hidden: true, .. Style::default() }
}
pub fn strikethrough(self) -> Style {
Style { foreground: Some(self), is_strikethrough: true, .. Style::default() }
}
pub fn on(self, background: Colour) -> Style {
Style { foreground: Some(self), background: Some(background), .. Style::default() }
}
}
impl From<Colour> for Style {
fn from(colour: Colour) -> Style {
colour.normal()
}
}