LIPH's C++ Codes
terminal.h
Go to the documentation of this file.
1#ifndef LIPH_TERMINAL_H_
2#define LIPH_TERMINAL_H_
3
4#include <cstdint>
5#include <string>
6
7#include "liph/format.h"
8
9namespace liph {
10
18
19enum class color256 : uint8_t {
20 Black = 0,
21 Maroon = 1,
22 Green = 2,
23 Olive = 3,
24 Navy = 4,
25 Purple = 5,
26 Teal = 6,
27 Silver = 7,
28 Grey = 8,
29 Red = 9,
30 Lime = 10,
31 Yellow = 11,
32 Blue = 12,
33 Fuchsia = 13,
34 Aqua = 14,
35 White = 15,
36 NavyBlue = 17,
37 DarkBlue = 18,
38 DarkGreen = 22,
39 DarkCyan = 36,
40 LightSeaGreen = 37,
41 DarkTurquoise = 44,
43 DarkRed = 52,
44 BlueViolet = 57,
45 SteelBlue = 67,
46 CornflowerBlue = 69,
47 CadetBlue = 72,
48 MediumTurquoise = 80,
49 DarkMagenta = 90,
50 DarkViolet = 92,
51 LightSlateGrey = 103,
52 MediumPurple = 104,
53 LightSlateBlue = 105,
54 DarkSeaGreen = 108,
55 LightGreen = 119,
56 MediumVioletRed = 126,
57 IndianRed = 131,
58 MediumOrchid = 134,
59 DarkGoldenrod = 136,
60 RosyBrown = 138,
61 DarkKhaki = 143,
62 LightSteelBlue = 147,
63 GreenYellow = 154,
64 Orchid = 170,
65 Violet = 177,
66 Tan = 180,
67 HotPink = 205,
68 DarkOrange = 208,
69 LightCoral = 210,
70 SandyBrown = 215
71};
72
73std::string color256fg(uint8_t);
74std::string color256bg(uint8_t);
75inline std::string color256fg(color256 c) { return color256fg(static_cast<uint8_t>(c)); }
76inline std::string color256bg(color256 c) { return color256bg(static_cast<uint8_t>(c)); }
77std::string color_reset();
78// https://en.wikipedia.org/wiki/ANSI_escape_code#Terminal_output_sequences
79inline std::string text_bold() { return "\033[01m"; }
80inline std::string text_faint() { return "\033[02m"; }
81inline std::string text_italic() { return "\033[03m"; }
82inline std::string text_underline() { return "\033[04m"; }
83inline std::string text_blink() { return "\033[05m"; }
84inline std::string text_rapid_blink() { return "\033[06m"; }
85inline std::string text_reverse() { return "\033[07m"; }
86inline std::string text_conceal() { return "\033[08m"; }
87inline std::string text_strikethrough() { return "\033[09m"; }
88
89struct rgb {
90 uint8_t r, g, b;
91 rgb() : rgb(0, 0, 0) {}
92 rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_), g(g_), b(b_) {}
93
94 std::string fg() const {
95 return format("\033[38;2;{};{};{}m", static_cast<int>(r), static_cast<int>(g), static_cast<int>(b));
96 }
97
98 std::string bg() const {
99 return format("\033[48;2;{};{};{}m", static_cast<int>(r), static_cast<int>(g), static_cast<int>(b));
100 }
101};
102
103} // namespace liph
104
105#endif // LIPH_TERMINAL_H_
Definition: algorithm.h:10
std::string text_strikethrough()
Definition: terminal.h:87
void clear_screen()
std::string text_rapid_blink()
Definition: terminal.h:84
bool stdin_echo_on()
std::string text_conceal()
Definition: terminal.h:86
std::string color256bg(unsigned char n)
Definition: terminal.cpp:48
std::string text_bold()
Definition: terminal.h:79
void clear_scrollback_buffer()
bool stdin_buffering_off()
bool stdin_echo_off()
void reset_screen()
std::string text_faint()
Definition: terminal.h:80
std::string color_reset()
Definition: terminal.cpp:49
std::string text_blink()
Definition: terminal.h:83
bool stdin_buffering_on()
std::string text_reverse()
Definition: terminal.h:85
std::string text_italic()
Definition: terminal.h:81
color256
Definition: terminal.h:19
std::string color256fg(unsigned char n)
Definition: terminal.cpp:47
std::string text_underline()
Definition: terminal.h:82
Definition: terminal.h:89
rgb()
Definition: terminal.h:91
uint8_t b
Definition: terminal.h:90
std::string bg() const
Definition: terminal.h:98
uint8_t g
Definition: terminal.h:90
rgb(uint8_t r_, uint8_t g_, uint8_t b_)
Definition: terminal.h:92
uint8_t r
Definition: terminal.h:90
std::string fg() const
Definition: terminal.h:94