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