use super::{BOLD, Color, DIM, ITALIC, REVERSE, Style, UNDERLINE};
impl Style {
#[must_use]
pub const fn foreground(mut self, color: Color) -> Self {
self.fg = Some(color);
self
}
#[must_use]
pub const fn background(mut self, color: Color) -> Self {
self.bg = Some(color);
self
}
#[must_use]
pub const fn bold(self, on: bool) -> Self {
self.with(BOLD, on)
}
#[must_use]
pub const fn faint(self, on: bool) -> Self {
self.with(DIM, on)
}
#[must_use]
pub const fn italic(self, on: bool) -> Self {
self.with(ITALIC, on)
}
#[must_use]
pub const fn underline(self, on: bool) -> Self {
self.with(UNDERLINE, on)
}
#[must_use]
pub const fn reverse(self, on: bool) -> Self {
self.with(REVERSE, on)
}
const fn with(mut self, bit: u8, on: bool) -> Self {
if on {
self.attributes |= bit;
} else {
self.attributes &= !bit;
}
self.chosen |= bit;
self
}
#[must_use]
pub const fn inherit(mut self, other: Self) -> Self {
if self.fg.is_none() {
self.fg = other.fg;
}
if self.bg.is_none() {
self.bg = other.bg;
}
self.inherit_attributes(other)
}
const fn inherit_attributes(mut self, other: Self) -> Self {
self.attributes |= other.attributes & !self.chosen;
self.chosen |= other.chosen;
self
}
#[must_use]
pub const fn plain(mut self) -> Self {
self.frame = Self::new().frame;
self
}
}
impl Style {
#[must_use]
#[deprecated(
since = "0.0.9",
note = "renamed to foreground, as Lip Gloss/Bubble Tea names it"
)]
pub const fn fg(self, color: Color) -> Self {
self.foreground(color)
}
#[must_use]
#[deprecated(
since = "0.0.9",
note = "renamed to background, as Lip Gloss/Bubble Tea names it"
)]
pub const fn bg(self, color: Color) -> Self {
self.background(color)
}
#[must_use]
#[deprecated(
since = "0.0.9",
note = "renamed to faint, as Lip Gloss/Bubble Tea names it"
)]
pub const fn dim(self, on: bool) -> Self {
self.faint(on)
}
}