FTXUI  5.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_SCREEN_COLOR_HPP
5#define FTXUI_SCREEN_COLOR_HPP
6
7#include <cstdint> // for uint8_t
8#include <string> // for string
9
10#ifdef RGB
11// Workaround for wingdi.h (via Windows.h) defining macros that break things.
12// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb
13#undef RGB
14#endif
15
16namespace ftxui {
17
18/// @brief A class representing terminal colors.
19/// @ingroup screen
20class Color {
21 public:
22 enum Palette1 : uint8_t;
23 enum Palette16 : uint8_t;
24 enum Palette256 : uint8_t;
25
26 // NOLINTBEGIN
27 Color(); // Transparent.
28 Color(Palette1 index); // Transparent.
29 Color(Palette16 index); // Implicit conversion from index to Color.
30 Color(Palette256 index); // Implicit conversion from index to Color.
31 // NOLINTEND
32 Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
33 static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
34 static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
35 static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
36 static Color HSVA(uint8_t hue,
37 uint8_t saturation,
38 uint8_t value,
40 static Color Interpolate(float t, const Color& a, const Color& b);
41 static Color Blend(const Color& lhs, const Color& rhs);
42
43 //---------------------------
44 // List of colors:
45 //---------------------------
46 // clang-format off
48 Default, // Transparent
49 };
50
69
74 Blue1 = 21,
75 Blue3 = 19,
87 Cornsilk1 = 230,
88 Cyan1 = 51,
89 Cyan2 = 50,
90 Cyan3 = 43,
95 DarkKhaki = 143,
142 Gold1 = 220,
143 Gold3 = 142,
144 Gold3Bis = 178,
145 Green1 = 46,
146 Green3 = 34,
148 Green4 = 28,
150 Grey0 = 16,
151 Grey100 = 231,
152 Grey11 = 234,
153 Grey15 = 235,
154 Grey19 = 236,
155 Grey23 = 237,
156 Grey27 = 238,
157 Grey3 = 232,
158 Grey30 = 239,
159 Grey35 = 240,
160 Grey37 = 59,
161 Grey39 = 241,
162 Grey42 = 242,
163 Grey46 = 243,
164 Grey50 = 244,
165 Grey53 = 102,
166 Grey54 = 245,
167 Grey58 = 246,
168 Grey62 = 247,
169 Grey63 = 139,
170 Grey66 = 248,
171 Grey69 = 145,
172 Grey7 = 233,
173 Grey70 = 249,
174 Grey74 = 250,
175 Grey78 = 251,
176 Grey82 = 252,
177 Grey84 = 188,
178 Grey85 = 253,
179 Grey89 = 254,
180 Grey93 = 255,
182 HotPink = 205,
183 HotPink2 = 169,
184 HotPink3 = 132,
191 Khaki1 = 228,
192 Khaki3 = 185,
219 Magenta1 = 201,
220 Magenta2 = 165,
222 Magenta3 = 127,
244 Orange1 = 214,
245 Orange3 = 172,
249 Orchid = 170,
250 Orchid1 = 213,
251 Orchid2 = 212,
259 Pink1 = 218,
260 Pink3 = 175,
261 Plum1 = 219,
262 Plum2 = 183,
263 Plum3 = 176,
264 Plum4 = 96,
265 Purple = 129,
270 Red1 = 196,
271 Red3 = 124,
272 Red3Bis = 160,
275 Salmon1 = 209,
281 SkyBlue1 = 117,
282 SkyBlue2 = 111,
297 Tan = 180,
298 Thistle1 = 225,
299 Thistle3 = 182,
302 Violet = 177,
303 Wheat1 = 229,
304 Wheat4 = 101,
305 Yellow1 = 226,
306 Yellow2 = 190,
307 Yellow3 = 148,
309 Yellow4 = 100,
311 };
312 // clang-format on
313
314 // --- Operators ------
315 bool operator==(const Color& rhs) const;
316 bool operator!=(const Color& rhs) const;
317
318 std::string Print(bool is_background_color) const;
319 bool IsOpaque() const { return alpha_ == 255; }
320
321 private:
322 enum class ColorType : uint8_t {
323 Palette1,
324 Palette16,
326 TrueColor,
327 };
328 ColorType type_ = ColorType::Palette1;
329 uint8_t red_ = 0;
330 uint8_t green_ = 0;
331 uint8_t blue_ = 0;
332 uint8_t alpha_ = 0;
333};
334
335inline namespace literals {
336
337/// @brief Creates a color from a combined hex RGB representation,
338/// e.g. 0x808000_rgb
339Color operator""_rgb(unsigned long long int combined);
340
341} // namespace literals
342
343} // namespace ftxui
344
345#endif // FTXUI_SCREEN_COLOR_HPP
A class representing terminal colors.
Definition color.hpp:20
Color()
Build a transparent color.
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value)
Build a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.
Definition color.cpp:207
static Color RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Build a Color from its RGBA representation. https://en.wikipedia.org/wiki/RGB_color_model.
Definition color.cpp:166
static Color Blend(const Color &lhs, const Color &rhs)
Blend two colors together using the alpha channel.
Definition color.cpp:281
bool operator!=(const Color &rhs) const
Definition color.cpp:42
bool operator==(const Color &rhs) const
Definition color.cpp:37
bool IsOpaque() const
Definition color.hpp:319
static Color RGB(uint8_t red, uint8_t green, uint8_t blue)
Build a Color from its RGB representation. https://en.wikipedia.org/wiki/RGB_color_model.
Definition color.cpp:153
@ LightGoldenrod2
Definition color.hpp:197
@ MediumOrchid1Bis
Definition color.hpp:227
@ DarkMagentaBis
Definition color.hpp:97
@ Chartreuse3Bis
Definition color.hpp:84
@ LightGoldenrod1
Definition color.hpp:196
@ MediumPurple3Bis
Definition color.hpp:234
@ LightGoldenrod3
Definition color.hpp:200
@ DarkSeaGreen4Bis
Definition color.hpp:117
@ LightSkyBlue3Bis
Definition color.hpp:212
@ DarkOliveGreen1
Definition color.hpp:98
@ Aquamarine1Bis
Definition color.hpp:72
@ DarkOliveGreen1Bis
Definition color.hpp:99
@ MediumPurple2Bis
Definition color.hpp:232
@ Chartreuse2Bis
Definition color.hpp:82
@ DarkSeaGreen1Bis
Definition color.hpp:111
@ MediumTurquoise
Definition color.hpp:237
@ DarkOliveGreen3Ter
Definition color.hpp:103
@ DarkSeaGreen3Bis
Definition color.hpp:115
@ LightSteelBlue1
Definition color.hpp:216
@ DeepSkyBlue3Bis
Definition color.hpp:135
@ MediumVioletRed
Definition color.hpp:238
@ LightGoldenrod2Ter
Definition color.hpp:199
@ DeepSkyBlue4Ter
Definition color.hpp:138
@ DarkOliveGreen2
Definition color.hpp:100
@ CornflowerBlue
Definition color.hpp:86
@ DarkGoldenrod
Definition color.hpp:93
@ LightGoldenrod2Bis
Definition color.hpp:198
@ DarkSeaGreen2Bis
Definition color.hpp:113
@ LightSalmon3Bis
Definition color.hpp:208
@ SpringGreen2Bis
Definition color.hpp:289
@ DeepSkyBlue4Bis
Definition color.hpp:137
@ DarkOliveGreen3Bis
Definition color.hpp:102
@ MediumSpringGreen
Definition color.hpp:236
@ DarkOliveGreen3
Definition color.hpp:101
@ SpringGreen3Bis
Definition color.hpp:291
@ LightSteelBlue3
Definition color.hpp:217
std::string Print(bool is_background_color) const
Definition color.cpp:46
static Color Interpolate(float t, const Color &a, const Color &b)
Definition color.cpp:212
static Color HSVA(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t alpha)
Build a Color from its HSV representation. https://en.wikipedia.org/wiki/HSL_and_HSV.
Definition color.cpp:179
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26