crossterm_style/enums/
attribute.rs

1use std::fmt::Display;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6use crate::SetAttr;
7
8/// Represents an attribute.
9///
10/// # Platform-specific Notes
11///
12/// * Only UNIX and Windows 10 terminals do support text attributes.
13/// * Keep in mind that not all terminals support all attributes.
14/// * Crossterm implements almost all attributes listed in the
15///   [SGR parameters](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters).
16///
17/// | Attribute | Windows | UNIX | Notes |
18/// | :-- | :--: | :--: | :-- |
19/// | `Reset` | ✓ | ✓ | |
20/// | `Bold` | ✓ | ✓ | |
21/// | `Dim` | ✓ | ✓ | |
22/// | `Italic` | ? | ? | Not widely supported, sometimes treated as inverse. |
23/// | `Underlined` | ✓ | ✓ | |
24/// | `SlowBlink` | ? | ? | Not widely supported, sometimes treated as inverse. |
25/// | `RapidBlink` | ? | ? | Not widely supported. MS-DOS ANSI.SYS; 150+ per minute. |
26/// | `Reverse` | ✓ | ✓ | |
27/// | `Hidden` | ✓ | ✓ | Also known as Conceal. |
28/// | `Fraktur` | ✗ | ✓ | Legible characters, but marked for deletion. |
29/// | `DefaultForegroundColor` | ? | ? | Implementation specific (according to standard). |
30/// | `DefaultBackgroundColor` | ? | ? | Implementation specific (according to standard). |
31/// | `Framed` | ? | ? | Not widely supported. |
32/// | `Encircled` | ? | ? | This should turn on the encircled attribute. |
33/// | `OverLined` | ? | ? | This should draw a line at the top of the text. |
34///
35/// # Examples
36///
37/// Basic usage:
38///
39/// ```no_run
40/// use crossterm_style::Attribute;
41///
42/// println!(
43///     "{} Underlined {} No Underline",
44///     Attribute::Underlined,
45///     Attribute::NoUnderline
46/// );
47/// ```
48///
49/// Style existing text:
50///
51/// ```no_run
52/// use crossterm_style::Styler;
53///
54/// println!("{}", "Bold text".bold());
55/// println!("{}", "Underlined text".underlined());
56/// println!("{}", "Negative text".negative());
57/// ```
58#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
59#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
60pub enum Attribute {
61    /// Resets all the attributes.
62    Reset = 0,
63    /// Increases the text intensity.
64    Bold = 1,
65    /// Decreases the text intensity.
66    Dim = 2,
67    /// Emphasises the text.
68    Italic = 3,
69    /// Underlines the text.
70    Underlined = 4,
71    /// Makes the text blinking (< 150 per minute).
72    SlowBlink = 5,
73    /// Makes the text blinking (>= 150 per minute).
74    RapidBlink = 6,
75    /// Swaps foreground and background colors.
76    Reverse = 7,
77    /// Hides the text (also known as Conceal).
78    Hidden = 8,
79    /// Crosses the text.
80    CrossedOut = 9,
81    /// Sets the [Fraktur](https://en.wikipedia.org/wiki/Fraktur) typeface.
82    ///
83    /// Mostly used for [mathematical alphanumeric symbols](https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols).
84    Fraktur = 20,
85    /// Turns off the `Bold` attribute.
86    NoBold = 21,
87    /// Switches the text back to normal intensity (no bold, italic).
88    NormalIntensity = 22,
89    /// Turns off the `Italic` attribute.
90    NoItalic = 23,
91    /// Turns off the `Underlined` attribute.
92    NoUnderline = 24,
93    /// Turns off the text blinking (`SlowBlink` or `RapidBlink`).
94    NoBlink = 25,
95    /// Turns off the `Reverse` attribute.
96    NoInverse = 27, // TODO Shouldn't we rename this to `NoReverse`? Or `Reverse` to `Inverse`?
97    /// Turns off the `Hidden` attribute.
98    NoHidden = 28,
99    /// Turns off the `CrossedOut` attribute.
100    NotCrossedOut = 29,
101    /// Makes the text framed.
102    Framed = 51,
103    /// Makes the text encircled.
104    Encircled = 52,
105    /// Draws a line at the top of the text.
106    OverLined = 53,
107    /// Turns off the `Frame` and `Encircled` attributes.
108    NotFramedOrEncircled = 54,
109    /// Turns off the `OverLined` attribute.
110    NotOverLined = 55,
111
112    #[doc(hidden)]
113    __Nonexhaustive,
114}
115
116impl Display for Attribute {
117    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
118        write!(f, "{}", SetAttr(*self))?;
119        Ok(())
120    }
121}