use std::fmt::Display;
use bitflags::bitflags;
use super::Color;
bitflags! {
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
pub struct Attributes: u8 {
const BOLD = 0b01;
const ITALIC = 0b10;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct StyleSheet {
pub fg: Option<Color>,
pub bg: Option<Color>,
pub att: Attributes,
}
impl StyleSheet {
pub fn new() -> Self {
Self::empty()
}
pub fn empty() -> Self {
Self {
fg: None,
bg: None,
att: Attributes::empty(),
}
}
pub fn is_empty(&self) -> bool {
self.fg.is_none() && self.bg.is_none() && self.att.is_empty()
}
pub fn with_fg(mut self, fg: Color) -> Self {
self.fg = Some(fg);
self
}
pub fn with_bg(mut self, bg: Color) -> Self {
self.bg = Some(bg);
self
}
pub fn with_attr(mut self, attributes: Attributes) -> Self {
self.att = attributes;
self
}
}
impl Default for StyleSheet {
fn default() -> Self {
Self::empty()
}
}
#[derive(Clone, Debug)]
pub struct Styled<T>
where
T: Display,
{
pub content: T,
pub style: StyleSheet,
}
impl<T> Styled<T>
where
T: Display,
{
pub fn new(content: T) -> Self {
Self {
content,
style: StyleSheet::default(),
}
}
#[allow(unused)]
pub fn with_style_sheet(mut self, style_sheet: StyleSheet) -> Self {
self.style = style_sheet;
self
}
pub fn with_fg(mut self, fg: Color) -> Self {
self.style.fg = Some(fg);
self
}
pub fn with_bg(mut self, bg: Color) -> Self {
self.style.bg = Some(bg);
self
}
pub fn with_attr(mut self, attributes: Attributes) -> Self {
self.style.att = attributes;
self
}
}
impl<T> Copy for Styled<T> where T: Copy + Display {}