use crate::core::color::Color;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
pub fg: Option<Color>,
pub bg: Option<Color>,
pub bold: bool,
pub italic: bool,
pub underlined: bool,
pub dim: bool,
}
impl Style {
pub const fn new() -> Self {
Self {
fg: None,
bg: None,
bold: false,
italic: false,
underlined: false,
dim: false,
}
}
pub const fn fg(mut self, fg: Color) -> Self {
self.fg = Some(fg);
self
}
pub const fn bg(mut self, bg: Color) -> Self {
self.bg = Some(bg);
self
}
pub const fn bold(mut self) -> Self {
self.bold = true;
self
}
pub const fn italic(mut self) -> Self {
self.italic = true;
self
}
pub const fn underlined(mut self) -> Self {
self.underlined = true;
self
}
pub const fn dim(mut self) -> Self {
self.dim = true;
self
}
pub fn merge(&self, other: &Style) -> Style {
Style {
fg: other.fg.or(self.fg),
bg: other.bg.or(self.bg),
bold: self.bold || other.bold,
italic: self.italic || other.italic,
underlined: self.underlined || other.underlined,
dim: self.dim || other.dim,
}
}
pub fn fg_or_default(&self) -> Color {
self.fg.unwrap_or(Color::WHITE)
}
}
impl Default for Style {
fn default() -> Self {
Self::new()
}
}
impl From<Color> for Style {
fn from(c: Color) -> Self {
Style::new().fg(c)
}
}