use crate::{TermColor, TermColors, TermStyle, Termel};
#[doc = crate::_tags!(term text color)]
#[doc = crate::_doc_meta!{
location("sys/os/term/grid"),
test_size_of(__: TermPen<devela::TermStyle, devela::TermColors> = 16|128)
}]
#[must_use]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct TermPen<S = TermStyle, C = TermColors> {
style: S,
colors: C,
}
impl TermPen {
pub const PLAIN: Self = Self::new(TermStyle::new(), TermColors::DEFAULT);
}
#[rustfmt::skip]
impl<S, C> TermPen<S, C> {
pub const fn new(style: S, colors: C) -> Self {
Self { style, colors }
}
#[must_use]
pub const fn style(&self) -> &S { &self.style }
#[must_use]
pub const fn colors(&self) -> &C { &self.colors }
pub const fn with_style<U>(self, style: U) -> TermPen<U, C> where Self: Copy {
TermPen::new(style, self.colors)
}
pub const fn with_colors<U>(self, colors: U) -> TermPen<S, U> where Self: Copy {
TermPen::new(self.style, colors)
}
pub const fn set_style(&mut self, style: S) where S: Copy { self.style = style; }
pub const fn set_colors(&mut self, colors: C) where C: Copy { self.colors = colors; }
pub const fn termel<T>(self, value: T) -> Termel<T, S, C> where Self: Copy {
Termel::from_value(value, self.style, self.colors)
}
}
#[rustfmt::skip]
impl<S> TermPen<S, TermColors> {
pub const fn fg(self) -> TermColor where Self: Copy { self.colors.fg() }
pub const fn bg(self) -> TermColor where Self: Copy { self.colors.bg() }
pub const fn with_fg(self, fg: TermColor) -> TermPen<S, TermColors> where Self: Copy {
TermPen::new(self.style, self.colors.with_fg(fg))
}
pub const fn with_bg(self, bg: TermColor) -> TermPen<S, TermColors> where Self: Copy {
TermPen::new(self.style, self.colors.with_bg(bg))
}
}