inquire/ui/color.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/// Represents a color to be used for text styling purposes.
///
/// Currently a clone of [crossterm::style::Color]. Check their documentation
/// for detailed documentation.
///
/// In summary, the 16 defined colors are supported by almost all terminals.
/// The Rgb and AnsiValue variants are supported in more modern ones.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Color {
/// Black color.
///
/// Ansi code reference: 0
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
Black,
/// Light red color.
///
/// Ansi code reference: 9
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkRed` color (Ansi code reference 1).
LightRed,
/// Dark red color.
///
/// Ansi code reference: 1
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkRed,
/// Light green color.
///
/// Ansi code reference: 10
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkGreen` color (Ansi code reference 2).
LightGreen,
/// Dark green color.
///
/// Ansi code reference: 2
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkGreen,
/// Light yellow color.
///
/// Ansi code reference: 11
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkYellow` color (Ansi code reference 3).
LightYellow,
/// Dark yellow color.
///
/// Ansi code reference: 3
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkYellow,
/// Light blue color.
///
/// Ansi code reference: 12
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkBlue` color (Ansi code reference 4).
LightBlue,
/// Dark blue color.
///
/// Ansi code reference: 4
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkBlue,
/// Light magenta color.
///
/// Ansi code reference: 13
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkMagenta` color (Ansi code reference 5).
LightMagenta,
/// Dark magenta color.
///
/// Ansi code reference: 5
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkMagenta,
/// Light cyan color.
///
/// Ansi code reference: 14
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `DarkCyan` color (Ansi code reference 6).
LightCyan,
/// Dark cyan color.
///
/// Ansi code reference: 6
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
DarkCyan,
/// White color.
///
/// Ansi code reference: 15
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `Grey` color (Ansi code reference 7).
White,
/// Grey color.
///
/// Ansi code reference: 7
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
Grey,
/// Dark grey color.
///
/// Ansi code reference: 8
///
/// Supported on two terminal back-ends: `crossterm` (the default) and `termion`.
/// On `console`, it is mapped to the `Black` color (Ansi code reference 0).
DarkGrey,
/// An RGB color. See [RGB color model](https://en.wikipedia.org/wiki/RGB_color_model) for more info.
///
/// Most UNIX terminals and Windows 10 supported only.
/// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info.
///
/// Supported on the default terminal back-end `crossterm` and on `termion`.
/// Not supported on `console`.
Rgb {
/// red value of RGB.
r: u8,
/// green value of RGB.
g: u8,
/// blue value of RGB.
b: u8,
},
/// An ANSI color. See [256 colors - cheat sheet](https://jonasjacek.github.io/colors/) for more info.
///
/// Most UNIX terminals and Windows 10 supported only.
/// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info.
///
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
AnsiValue(u8),
}
impl Color {
/// Shorthand method for creating a Color from RGB components
///
/// ```
/// # use inquire::ui::Color;
///
/// assert_eq!(Color::rgb(42, 17, 97), Color::Rgb { r: 42, g: 17, b: 97 });
/// ```
pub fn rgb(r: u8, g: u8, b: u8) -> Color {
Color::Rgb { r, g, b }
}
}