comfy_table/style/
attribute.rs

1/// Represents an attribute.
2///
3/// # Platform-specific Notes
4///
5/// * Only UNIX and Windows 10 terminals do support text attributes.
6/// * Keep in mind that not all terminals support all attributes.
7/// * Crossterm implements almost all attributes listed in the
8///   [SGR parameters](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters).
9///
10/// | Attribute | Windows | UNIX | Notes |
11/// | :-- | :--: | :--: | :-- |
12/// | `Reset` | ✓ | ✓ | |
13/// | `Bold` | ✓ | ✓ | |
14/// | `Dim` | ✓ | ✓ | |
15/// | `Italic` | ? | ? | Not widely supported, sometimes treated as inverse. |
16/// | `Underlined` | ✓ | ✓ | |
17/// | `SlowBlink` | ? | ? | Not widely supported, sometimes treated as inverse. |
18/// | `RapidBlink` | ? | ? | Not widely supported. MS-DOS ANSI.SYS; 150+ per minute. |
19/// | `Reverse` | ✓ | ✓ | |
20/// | `Hidden` | ✓ | ✓ | Also known as Conceal. |
21/// | `Fraktur` | ✗ | ✓ | Legible characters, but marked for deletion. |
22/// | `DefaultForegroundColor` | ? | ? | Implementation specific (according to standard). |
23/// | `DefaultBackgroundColor` | ? | ? | Implementation specific (according to standard). |
24/// | `Framed` | ? | ? | Not widely supported. |
25/// | `Encircled` | ? | ? | This should turn on the encircled attribute. |
26/// | `OverLined` | ? | ? | This should draw a line at the top of the text. |
27///
28/// Usage:
29///
30/// Check [crate::Cell::add_attribute] on how to use it.
31#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
32#[non_exhaustive]
33pub enum Attribute {
34    /// Resets all the attributes.
35    Reset,
36    /// Increases the text intensity.
37    Bold,
38    /// Decreases the text intensity.
39    Dim,
40    /// Emphasises the text.
41    Italic,
42    /// Underlines the text.
43    Underlined,
44
45    // Other types of underlining
46    /// Double underlines the text.
47    DoubleUnderlined,
48    /// Undercurls the text.
49    Undercurled,
50    /// Underdots the text.
51    Underdotted,
52    /// Underdashes the text.
53    Underdashed,
54
55    /// Makes the text blinking (< 150 per minute).
56    SlowBlink,
57    /// Makes the text blinking (>= 150 per minute).
58    RapidBlink,
59    /// Swaps foreground and background colors.
60    Reverse,
61    /// Hides the text (also known as Conceal).
62    Hidden,
63    /// Crosses the text.
64    CrossedOut,
65    /// Sets the [Fraktur](https://en.wikipedia.org/wiki/Fraktur) typeface.
66    ///
67    /// Mostly used for [mathematical alphanumeric symbols](https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols).
68    Fraktur,
69    /// Turns off the `Bold` attribute. - Inconsistent - Prefer to use NormalIntensity
70    NoBold,
71    /// Switches the text back to normal intensity (no bold, italic).
72    NormalIntensity,
73    /// Turns off the `Italic` attribute.
74    NoItalic,
75    /// Turns off the `Underlined` attribute.
76    NoUnderline,
77    /// Turns off the text blinking (`SlowBlink` or `RapidBlink`).
78    NoBlink,
79    /// Turns off the `Reverse` attribute.
80    NoReverse,
81    /// Turns off the `Hidden` attribute.
82    NoHidden,
83    /// Turns off the `CrossedOut` attribute.
84    NotCrossedOut,
85    /// Makes the text framed.
86    Framed,
87    /// Makes the text encircled.
88    Encircled,
89    /// Draws a line at the top of the text.
90    OverLined,
91    /// Turns off the `Frame` and `Encircled` attributes.
92    NotFramedOrEncircled,
93    /// Turns off the `OverLined` attribute.
94    NotOverLined,
95}
96
97/// Map the internal mirrored [Attribute] to the actually used [crossterm::style::Attribute]
98pub(crate) fn map_attribute(attribute: Attribute) -> crossterm::style::Attribute {
99    match attribute {
100        Attribute::Reset => crossterm::style::Attribute::Reset,
101        Attribute::Bold => crossterm::style::Attribute::Bold,
102        Attribute::Dim => crossterm::style::Attribute::Dim,
103        Attribute::Italic => crossterm::style::Attribute::Italic,
104        Attribute::Underlined => crossterm::style::Attribute::Underlined,
105        Attribute::DoubleUnderlined => crossterm::style::Attribute::DoubleUnderlined,
106        Attribute::Undercurled => crossterm::style::Attribute::Undercurled,
107        Attribute::Underdotted => crossterm::style::Attribute::Underdotted,
108        Attribute::Underdashed => crossterm::style::Attribute::Underdashed,
109        Attribute::SlowBlink => crossterm::style::Attribute::SlowBlink,
110        Attribute::RapidBlink => crossterm::style::Attribute::RapidBlink,
111        Attribute::Reverse => crossterm::style::Attribute::Reverse,
112        Attribute::Hidden => crossterm::style::Attribute::Hidden,
113        Attribute::CrossedOut => crossterm::style::Attribute::CrossedOut,
114        Attribute::Fraktur => crossterm::style::Attribute::Fraktur,
115        Attribute::NoBold => crossterm::style::Attribute::NoBold,
116        Attribute::NormalIntensity => crossterm::style::Attribute::NormalIntensity,
117        Attribute::NoItalic => crossterm::style::Attribute::NoItalic,
118        Attribute::NoUnderline => crossterm::style::Attribute::NoUnderline,
119        Attribute::NoBlink => crossterm::style::Attribute::NoBlink,
120        Attribute::NoReverse => crossterm::style::Attribute::NoReverse,
121        Attribute::NoHidden => crossterm::style::Attribute::NoHidden,
122        Attribute::NotCrossedOut => crossterm::style::Attribute::NotCrossedOut,
123        Attribute::Framed => crossterm::style::Attribute::Framed,
124        Attribute::Encircled => crossterm::style::Attribute::Encircled,
125        Attribute::OverLined => crossterm::style::Attribute::OverLined,
126        Attribute::NotFramedOrEncircled => crossterm::style::Attribute::NotFramedOrEncircled,
127        Attribute::NotOverLined => crossterm::style::Attribute::NotOverLined,
128    }
129}