terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tgcolor.h
1 #pragma once
2 
3 #include <QString>
4 #include <QMetaType>
5 
6 namespace Tg {
20 class Color {
21 public:
34  enum class Predefined {
36  Invalid = -1,
38  Empty = 0,
40  Black = 30,
42  Red = 31,
44  Green = 32,
46  Yellow = 33,
48  Blue = 34,
50  Magenta = 35,
52  Cyan = 36,
54  White = 37,
56  Gray = 90,
58  Pink = 91,
59  LightRed = Pink,
61  LightGreen = 92,
63  LightYellow = 93,
65  LightBlue = 94,
67  LightMagenta = 95,
69  LightCyan = 96,
73  LightWhite = 97
74  };
75 
83  static QString code(const Color &foreground,
84  const Color &background = Color::Predefined::Empty);
85 
94  static QString code(const Color &color, const bool isBackground,
95  const bool forceTrueColor);
96 
100  static QString end();
101 
105  Color();
106 
113  Color(const Predefined predefined);
114 
123  Color(const quint8 red, const quint8 green, const quint8 blue);
124 
134  QString rgb() const;
135 
141  quint8 red() const;
142 
148  quint8 green() const;
149 
155  quint8 blue() const;
156 
161  Predefined predefined() const;
162 
167  bool isEmpty() const;
168 
174  bool isPredefined() const;
175 
181  bool isTrueColor() const;
182 
186  bool operator==(const Color &other) const;
187 
191  bool operator!=(const Color &other) const;
192 
193 private:
194  int predefinedValue() const;
195 
196  quint8 _red = 0;
197  quint8 _green = 0;
198  quint8 _blue = 0;
199 
200  Predefined _predefined = Predefined::Invalid;
201 };
202 }
203 
204 Q_DECLARE_METATYPE(Tg::Color)
Tg::Color::operator==
bool operator==(const Color &other) const
Returns true is other is the same.
Definition: tgcolor.cpp:103
Tg::Color::Predefined::Black
@ Black
Default black color, depends on terminal settings.
Tg::Color::isTrueColor
bool isTrueColor() const
Returns true if Color is 24 bit (as opposed to Predefined).
Definition: tgcolor.cpp:98
Tg::Color::blue
quint8 blue() const
Returns intensity of blue color.
Definition: tgcolor.cpp:72
Tg::Color::red
quint8 red() const
Returns intensity of red color.
Definition: tgcolor.cpp:62
Tg::Color::predefined
Predefined predefined() const
Returns a Predefined color value if Color is not 24 bit, or Predefined::Invalid otherwise.
Definition: tgcolor.cpp:77
Tg::Color::Predefined::LightWhite
@ LightWhite
Tg::Color::Predefined::Red
@ Red
Default red color, depends on terminal settings.
Tg::Color::Predefined::LightCyan
@ LightCyan
Default lighter cyan color, depends on terminal settings.
Tg::Color::end
static QString end()
Returns ANSI sequence which ends color definition.
Definition: tgcolor.cpp:50
Tg::Color::Predefined::LightYellow
@ LightYellow
Default lighter yellow color, depends on terminal settings.
Tg::Color::Predefined
Predefined
Contains predefined colors supported by all terminals, including the oldest ones.
Definition: tgcolor.h:34
Tg
All Terminal GUI classes (both core and widgets) are defined within the Tg namespace.
Definition: tgcolor.h:6
Tg::Color::Predefined::White
@ White
Default white color, depends on terminal settings.
Tg::Color::rgb
QString rgb() const
Returns 24 bit color information in a format understood by the terminal.
Definition: tgcolor.cpp:55
Tg::Color::Predefined::Blue
@ Blue
Default blue color, depends on terminal settings.
Tg::Color::Predefined::Pink
@ Pink
Default pink color, depends on terminal settings.
Tg::Color::Predefined::Invalid
@ Invalid
Color is not defined and cannot be drawn. Used to indicate unset colors.
Tg::Color::Predefined::Empty
@ Empty
Color is defined as empty - default terminal color will be used.
Tg::Color
Represents colors in a terminal.
Definition: tgcolor.h:20
Tg::Color::isPredefined
bool isPredefined() const
Returns true is Color type is Predefined (as opposed to 24 bit color).
Definition: tgcolor.cpp:93
Tg::Color::operator!=
bool operator!=(const Color &other) const
Returns true if other is different.
Definition: tgcolor.cpp:114
Tg::Color::Predefined::Yellow
@ Yellow
Default yellow color, depends on terminal settings.
Tg::Color::Predefined::Magenta
@ Magenta
Default magenta color, depends on terminal settings.
Tg::Color::Predefined::Cyan
@ Cyan
Default cyan color, depends on terminal settings.
Tg::Color::Predefined::Gray
@ Gray
Default gray color, depends on terminal settings.
Tg::Color::code
static QString code(const Color &foreground, const Color &background=Color::Predefined::Empty)
Returns ANSI-coded sequence, as understood by terminal, for given foreground color and background col...
Definition: tgcolor.cpp:19
Tg::Color::Color
Color()
Constructs a color of type Predefined (it's set to Predefined::Invalid).
Definition: tgcolor.cpp:5
Tg::Color::Predefined::LightGreen
@ LightGreen
Default lighter green color, depends on terminal settings.
Tg::Color::Predefined::LightMagenta
@ LightMagenta
Default lighter magenta color, depends on terminal settings.
Tg::Color::green
quint8 green() const
Returns intensity of green color.
Definition: tgcolor.cpp:67
Tg::Color::Predefined::Green
@ Green
Default green color, depends on terminal settings.
Tg::Color::Predefined::LightBlue
@ LightBlue
Default lighter blue color, depends on terminal settings.
Tg::Color::isEmpty
bool isEmpty() const
Returns true if a Predefined color is Predefined::Empty.
Definition: tgcolor.cpp:82