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