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#include <vector> // for vector
10
11#ifdef RGB
12// Workaround for wingdi.h (via Windows.h) defining macros that break things.
13// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rgb
14#undef RGB
15#endif
16
17namespace ftxui {
18
19/// @brief A class representing terminal colors.
20/// @ingroup screen
21class Color {
22 public:
23 enum Palette1 : uint8_t;
24 enum Palette16 : uint8_t;
25 enum Palette256 : uint8_t;
26
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 Color(uint8_t red, uint8_t green, uint8_t blue);
32 static Color RGB(uint8_t red, uint8_t green, uint8_t blue);
33 static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value);
34 static Color Interpolate(float t, const Color& a, const Color& b);
35
36 //---------------------------
37 // List of colors:
38 //---------------------------
39 // clang-format off
41 Default, // Transparent
42 };
43
62
67 Blue1 = 21,
68 Blue3 = 19,
80 Cornsilk1 = 230,
81 Cyan1 = 51,
82 Cyan2 = 50,
83 Cyan3 = 43,
88 DarkKhaki = 143,
135 Gold1 = 220,
136 Gold3 = 142,
137 Gold3Bis = 178,
138 Green1 = 46,
139 Green3 = 34,
141 Green4 = 28,
143 Grey0 = 16,
144 Grey100 = 231,
145 Grey11 = 234,
146 Grey15 = 235,
147 Grey19 = 236,
148 Grey23 = 237,
149 Grey27 = 238,
150 Grey3 = 232,
151 Grey30 = 239,
152 Grey35 = 240,
153 Grey37 = 59,
154 Grey39 = 241,
155 Grey42 = 242,
156 Grey46 = 243,
157 Grey50 = 244,
158 Grey53 = 102,
159 Grey54 = 245,
160 Grey58 = 246,
161 Grey62 = 247,
162 Grey63 = 139,
163 Grey66 = 248,
164 Grey69 = 145,
165 Grey7 = 233,
166 Grey70 = 249,
167 Grey74 = 250,
168 Grey78 = 251,
169 Grey82 = 252,
170 Grey84 = 188,
171 Grey85 = 253,
172 Grey89 = 254,
173 Grey93 = 255,
175 HotPink = 205,
176 HotPink2 = 169,
177 HotPink3 = 132,
184 Khaki1 = 228,
185 Khaki3 = 185,
212 Magenta1 = 201,
213 Magenta2 = 165,
215 Magenta3 = 127,
237 Orange1 = 214,
238 Orange3 = 172,
242 Orchid = 170,
243 Orchid1 = 213,
244 Orchid2 = 212,
252 Pink1 = 218,
253 Pink3 = 175,
254 Plum1 = 219,
255 Plum2 = 183,
256 Plum3 = 176,
257 Plum4 = 96,
258 Purple = 129,
263 Red1 = 196,
264 Red3 = 124,
265 Red3Bis = 160,
268 Salmon1 = 209,
274 SkyBlue1 = 117,
275 SkyBlue2 = 111,
290 Tan = 180,
291 Thistle1 = 225,
292 Thistle3 = 182,
295 Violet = 177,
296 Wheat1 = 229,
297 Wheat4 = 101,
298 Yellow1 = 226,
299 Yellow2 = 190,
300 Yellow3 = 148,
302 Yellow4 = 100,
304 };
305 // clang-format on
306
307 // --- Operators ------
308 bool operator==(const Color& rhs) const;
309 bool operator!=(const Color& rhs) const;
310
311 std::string Print(bool is_background_color) const;
312
313 private:
314 enum class ColorType : uint8_t {
315 Palette1,
316 Palette16,
318 TrueColor,
319 };
320 ColorType type_ = ColorType::Palette1;
321 uint8_t red_ = 0;
322 uint8_t green_ = 0;
323 uint8_t blue_ = 0;
324};
325
326inline namespace literals {
327
328/// @brief Creates a color from a combined hex RGB representation,
329/// e.g. 0x808000_rgb
330Color operator""_rgb(unsigned long long int combined);
331
332} // namespace literals
333
334} // namespace ftxui
335
336#endif // FTXUI_SCREEN_COLOR_HPP
A class representing terminal colors.
Definition color.hpp:21
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:151
bool operator!=(const Color &rhs) const
Definition color.cpp:45
bool operator==(const Color &rhs) const
Definition color.cpp:40
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:139
@ LightGoldenrod2
Definition color.hpp:190
@ MediumOrchid1Bis
Definition color.hpp:220
@ DarkMagentaBis
Definition color.hpp:90
@ Chartreuse3Bis
Definition color.hpp:77
@ LightGoldenrod1
Definition color.hpp:189
@ MediumPurple3Bis
Definition color.hpp:227
@ LightGoldenrod3
Definition color.hpp:193
@ DarkSeaGreen4Bis
Definition color.hpp:110
@ LightSkyBlue3Bis
Definition color.hpp:205
@ DarkOrange3Bis
Definition color.hpp:99
@ DarkOliveGreen1
Definition color.hpp:91
@ Aquamarine1Bis
Definition color.hpp:65
@ DarkOliveGreen1Bis
Definition color.hpp:92
@ MediumPurple2Bis
Definition color.hpp:225
@ Chartreuse2Bis
Definition color.hpp:75
@ DarkSeaGreen1Bis
Definition color.hpp:104
@ MediumTurquoise
Definition color.hpp:230
@ DarkOliveGreen3Ter
Definition color.hpp:96
@ DarkSeaGreen3Bis
Definition color.hpp:108
@ LightSteelBlue1
Definition color.hpp:209
@ DeepSkyBlue3Bis
Definition color.hpp:128
@ MediumVioletRed
Definition color.hpp:231
@ LightGoldenrod2Ter
Definition color.hpp:192
@ DeepSkyBlue4Ter
Definition color.hpp:131
@ DarkOliveGreen2
Definition color.hpp:93
@ CornflowerBlue
Definition color.hpp:79
@ DarkGoldenrod
Definition color.hpp:86
@ LightGoldenrod2Bis
Definition color.hpp:191
@ DarkSeaGreen2Bis
Definition color.hpp:106
@ LightSalmon3Bis
Definition color.hpp:201
@ SpringGreen2Bis
Definition color.hpp:282
@ DeepSkyBlue4Bis
Definition color.hpp:130
@ DarkOliveGreen3Bis
Definition color.hpp:95
@ MediumSpringGreen
Definition color.hpp:229
@ DarkOliveGreen3
Definition color.hpp:94
@ SpringGreen3Bis
Definition color.hpp:284
@ LightSteelBlue3
Definition color.hpp:210
std::string Print(bool is_background_color) const
Definition color.cpp:49
static Color Interpolate(float t, const Color &a, const Color &b)
Definition color.cpp:176
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition slider.cpp:339