macro_rules! impl_additive_styling_type {
($name:ident {
args: [$self:ident];
to_style: $to_style:tt
}) => {
impl $name {
$crate::impl_macros::additive_styling::impl_additive_styling_methods!();
#[must_use]
pub fn applied_to<C: core::fmt::Display>(self, content: C) -> $crate::Styled<C> {
let style = $crate::Style::from(self);
$crate::Styled::new(content).with_style(style)
}
}
$crate::impl_macros::additive_styling::__impl_additive_styling_type__to_style!(
$name, $self, $to_style
);
};
}
pub(crate) use impl_additive_styling_type;
macro_rules! impl_additive_styling_methods {
() => {
$crate::impl_macros::additive_styling::impl_additive_styling_methods! {
type ComposedStyling = $crate::Style;
args: [self];
to_composed_styling: { self.to_style() }
}
};
{
type ComposedStyling = $composed_styling_type:ty;
args: [$self:ident];
to_composed_styling: $to_composed_styling:block
} => {
#[must_use]
pub fn bold(self) -> $composed_styling_type {
self.effect($crate::Effect::Bold)
}
#[must_use]
pub fn faint(self) -> $composed_styling_type {
self.effect($crate::Effect::Faint)
}
#[must_use]
pub fn italic(self) -> $composed_styling_type {
self.effect($crate::Effect::Italic)
}
#[must_use]
pub fn underline(self) -> $composed_styling_type {
self.solid_underline()
}
#[must_use]
pub fn solid_underline(self) -> $composed_styling_type {
self.effect($crate::Effect::SolidUnderline)
}
#[must_use]
pub fn curly_underline(self) -> $composed_styling_type {
self.effect($crate::Effect::CurlyUnderline)
}
#[must_use]
pub fn dotted_underline(self) -> $composed_styling_type {
self.effect($crate::Effect::DottedUnderline)
}
#[must_use]
pub fn dashed_underline(self) -> $composed_styling_type {
self.effect($crate::Effect::DashedUnderline)
}
#[must_use]
pub fn blink(self) -> $composed_styling_type {
self.effect($crate::Effect::Blink)
}
#[must_use]
pub fn reverse(self) -> $composed_styling_type {
self.effect($crate::Effect::Reverse)
}
#[must_use]
pub fn conceal(self) -> $composed_styling_type {
self.effect($crate::Effect::Conceal)
}
#[must_use]
pub fn strikethrough(self) -> $composed_styling_type {
self.effect($crate::Effect::Strikethrough)
}
#[must_use]
pub fn double_underline(self) -> $composed_styling_type {
self.effect($crate::Effect::DoubleUnderline)
}
#[must_use]
pub fn overline(self) -> $composed_styling_type {
self.effect($crate::Effect::Overline)
}
#[must_use]
pub fn effect(self, effect: impl Into<$crate::Effect>) -> $composed_styling_type {
self.to_composed_styling().set_effect(effect, true)
}
#[must_use]
pub fn underline_effect(self, underline_effect: $crate::UnderlineEffect) -> $composed_styling_type {
self.effect(underline_effect)
}
#[must_use]
pub fn fg(self, color: impl Into<$crate::color::Color>) -> $composed_styling_type {
self.color($crate::TargetedColor::new_for_fg(color))
}
#[must_use]
pub fn bg(self, color: impl Into<$crate::color::Color>) -> $composed_styling_type {
self.color($crate::TargetedColor::new_for_bg(color))
}
#[must_use]
pub fn underline_color(self, color: impl Into<$crate::color::Color>) -> $composed_styling_type {
self.color($crate::TargetedColor::new_for_underline(color))
}
#[must_use]
pub fn color(
self,
targeted_color: impl Into<$crate::TargetedColor>,
) -> $composed_styling_type {
let targeted_color = targeted_color.into();
self.to_composed_styling().set_color(
targeted_color.get_target(),
Some(targeted_color.get_color()),
)
}
#[expect(clippy::should_implement_trait)]
#[must_use]
pub fn add(self, element: impl $crate::StylingElement<$composed_styling_type>) -> $composed_styling_type {
let composed_styling = self.to_composed_styling();
element.add_to(composed_styling)
}
#[allow(clippy::wrong_self_convention)]
#[must_use]
fn to_composed_styling($self) -> $composed_styling_type $to_composed_styling
};
}
pub(crate) use impl_additive_styling_methods;
macro_rules! __impl_additive_styling_type__to_style {
($name:ident, $self:ident, SELF) => {
impl $name {
#[doc = r"Convert this type into a [`Style`](crate::Style)."]
#[must_use]
pub fn to_style(self) -> Style {
self
}
}
};
($name:ident, $self:ident, $to_style:tt ) => {
$crate::impl_macros::from_to::impl_from_to!(
#[doc = r"Converts the type into a [`Style`](crate::Style)."]
fn to_style($self: $name) -> $crate::Style $to_style
);
};
}
pub(crate) use __impl_additive_styling_type__to_style;