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