comfy_table/style/
color.rs

1/// Represents a color.
2///
3/// This type is a simplified re-implementation of crossterm's Color enum.
4/// See [crossterm::style::color](https://docs.rs/crossterm/latest/crossterm/style/enum.Color.html)
5///
6/// # Platform-specific Notes
7///
8/// The following list of 16 base colors are available for almost all terminals (Windows 7 and 8 included).
9///
10/// | Light      | Dark          |
11/// | :--------- | :------------ |
12/// | `DarkGrey` | `Black`       |
13/// | `Red`      | `DarkRed`     |
14/// | `Green`    | `DarkGreen`   |
15/// | `Yellow`   | `DarkYellow`  |
16/// | `Blue`     | `DarkBlue`    |
17/// | `Magenta`  | `DarkMagenta` |
18/// | `Cyan`     | `DarkCyan`    |
19/// | `White`    | `Grey`        |
20///
21/// Most UNIX terminals and Windows 10 consoles support additional colors.
22/// See [Color::Rgb] or [Color::AnsiValue] for more info.
23///
24/// Usage:
25///
26/// Check [crate::Cell::bg], [crate::Cell::fg] and  on how to use it.
27#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
28pub enum Color {
29    /// Resets the terminal color.
30    Reset,
31
32    /// Black color.
33    Black,
34
35    /// Dark grey color.
36    DarkGrey,
37
38    /// Light red color.
39    Red,
40
41    /// Dark red color.
42    DarkRed,
43
44    /// Light green color.
45    Green,
46
47    /// Dark green color.
48    DarkGreen,
49
50    /// Light yellow color.
51    Yellow,
52
53    /// Dark yellow color.
54    DarkYellow,
55
56    /// Light blue color.
57    Blue,
58
59    /// Dark blue color.
60    DarkBlue,
61
62    /// Light magenta color.
63    Magenta,
64
65    /// Dark magenta color.
66    DarkMagenta,
67
68    /// Light cyan color.
69    Cyan,
70
71    /// Dark cyan color.
72    DarkCyan,
73
74    /// White color.
75    White,
76
77    /// Grey color.
78    Grey,
79
80    /// An RGB color. See [RGB color model](https://en.wikipedia.org/wiki/RGB_color_model) for more info.
81    ///
82    /// Most UNIX terminals and Windows 10 supported only.
83    /// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info.
84    Rgb { r: u8, g: u8, b: u8 },
85
86    /// An ANSI color. See [256 colors - cheat sheet](https://jonasjacek.github.io/colors/) for more info.
87    ///
88    /// Most UNIX terminals and Windows 10 supported only.
89    /// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info.
90    AnsiValue(u8),
91}
92
93/// Map the internal mirrored [Color] enum to the actually used [crossterm::style::Color].
94pub(crate) fn map_color(color: Color) -> crossterm::style::Color {
95    match color {
96        Color::Reset => crossterm::style::Color::Reset,
97        Color::Black => crossterm::style::Color::Black,
98        Color::DarkGrey => crossterm::style::Color::DarkGrey,
99        Color::Red => crossterm::style::Color::Red,
100        Color::DarkRed => crossterm::style::Color::DarkRed,
101        Color::Green => crossterm::style::Color::Green,
102        Color::DarkGreen => crossterm::style::Color::DarkGreen,
103        Color::Yellow => crossterm::style::Color::Yellow,
104        Color::DarkYellow => crossterm::style::Color::DarkYellow,
105        Color::Blue => crossterm::style::Color::Blue,
106        Color::DarkBlue => crossterm::style::Color::DarkBlue,
107        Color::Magenta => crossterm::style::Color::Magenta,
108        Color::DarkMagenta => crossterm::style::Color::DarkMagenta,
109        Color::Cyan => crossterm::style::Color::Cyan,
110        Color::DarkCyan => crossterm::style::Color::DarkCyan,
111        Color::White => crossterm::style::Color::White,
112        Color::Grey => crossterm::style::Color::Grey,
113        Color::Rgb { r, g, b } => crossterm::style::Color::Rgb { r, g, b },
114        Color::AnsiValue(value) => crossterm::style::Color::AnsiValue(value),
115    }
116}