fluent_ansi/effect/
underline.rs1use core::fmt::{Display, Formatter, Result};
2
3use enum_iterator::Sequence;
4
5use crate::{
6 Effect,
7 impl_macros::{additive_styling::impl_additive_styling_type, from_to::impl_from_to},
8 impl_styling_atribute_for, impl_styling_element_for,
9};
10
11pub(crate) type AllUnderlineEffects = enum_iterator::All<UnderlineEffect>;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Sequence)]
17pub enum UnderlineEffect {
18 #[default]
20 Solid,
21 Curly,
23 Dotted,
25 Dashed,
27 Double,
29}
30
31impl UnderlineEffect {
32 #[must_use]
33 pub(crate) fn all() -> AllUnderlineEffects {
34 enum_iterator::all()
35 }
36}
37
38impl_additive_styling_type!(UnderlineEffect {
39 args: [self];
40 to_style: { self.to_effect().to_style() }
41});
42
43impl_from_to!(
44 #[doc = r"Converts the type into an [`Effect`]."]
45 fn to_effect(self: UnderlineEffect) -> Effect {
46 match self {
47 UnderlineEffect::Solid => Effect::SolidUnderline,
48 UnderlineEffect::Curly => Effect::CurlyUnderline,
49 UnderlineEffect::Dotted => Effect::DottedUnderline,
50 UnderlineEffect::Dashed => Effect::DashedUnderline,
51 UnderlineEffect::Double => Effect::DoubleUnderline,
52 }
53 }
54);
55
56impl Display for UnderlineEffect {
57 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
58 self.to_effect().fmt(f)
59 }
60}
61
62impl_styling_element_for! { UnderlineEffect {
63 args: [self, composed_styling];
64 add_to: {
65 composed_styling.set_underline_effect(Some(self))
66 }
67}}
68
69impl_styling_atribute_for! { UnderlineEffect {
70 type Value = bool;
71 args: [self, composed_styling, value];
72
73 set_in: {
74 composed_styling.set_effect(self.to_effect(), value)
75 }
76
77 get_from: {
78 composed_styling.get_effect(self.to_effect())
79 }
80}}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
88pub struct UnderlineStyle;
89
90impl_styling_atribute_for! { UnderlineStyle {
91 type Value = Option<UnderlineEffect>;
92 args: [self, composed_styling, value];
93
94 set_in: {
95 composed_styling.set_underline_effect(value)
96 }
97
98 get_from: {
99 composed_styling.get_underline_effect()
100 }
101}}