mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
terminal.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <mutable/mutable-config.hpp>
5
6
7namespace m::term {
8
9/*----- Common control codes. ----------------------------------------------------------------------------------------*/
10
11/* 0 reset all attributes to their defaults */
12constexpr const char *RESET = "\033[0m";
13/* 1 set bold */
14constexpr const char *BOLD = "\033[1m";
15/* 2 set half-bright (simulated with color on a color display) */
16constexpr const char *HALF_BRIGHT = "\033[2m";
17/* 3 set italic */
18constexpr const char *ITALIC = "\033[3m";
19/* 4 set underscore (simulated with color on a color display) (the colors used to simulate dim or underline are
20 * set using ESC ] ...) */
21constexpr const char *UNDERLINE = "\033[4m";
22/* 5 set blink */
23constexpr const char *BLINK = "\033[5m";
24/* 7 set reverse video */
25constexpr const char *REVERSE = "\033[7m";
26/* 21 set normal intensity (ECMA-48 says "doubly underlined") */
27constexpr const char *DOUBLE_UNDERLINE = "\033[21m";
28/* 22 set normal intensity */
29constexpr const char *NORMAL = "\033[22m";
30/* 24 underline off */
31constexpr const char *UNDERLINE_OFF = "\033[24m";
32/* 25 blink off */
33constexpr const char *BLINK_OFF = "\033[25m";
34/* 27 reverse video off */
35constexpr const char *REVERSE_OFF = "\033[27m";
36/* 30 set black foreground */
37constexpr const char *FG_BLACK = "\033[30m";
38/* 31 set red foreground */
39constexpr const char *FG_RED = "\033[31m";
40/* 32 set green foreground */
41constexpr const char *FG_GREEN = "\033[32m";
42/* 33 set brown foreground */
43constexpr const char *FG_YELLOW = "\033[33m";
44/* 34 set blue foreground */
45constexpr const char *FG_BLUE = "\033[34m";
46/* 35 set magenta foreground */
47constexpr const char *FG_MAGENTA = "\033[35m";
48/* 36 set cyan foreground */
49constexpr const char *FG_CYAN = "\033[36m";
50/* 37 set white foreground */
51constexpr const char *FG_WHITE = "\033[37m";
52/* 40 set black background */
53constexpr const char *BG_BLACK = "\033[40m";
54/* 41 set red background */
55constexpr const char *BG_RED = "\033[41m";
56/* 42 set green background */
57constexpr const char *BG_GREEN = "\033[42m";
58/* 43 set brown background */
59constexpr const char *BG_YELLOW = "\033[43m";
60/* 44 set blue background */
61constexpr const char *BG_BLUE = "\033[44m";
62/* 45 set magenta background */
63constexpr const char *BG_MAGENTA = "\033[45m";
64/* 46 set cyan background */
65constexpr const char *BG_CYAN = "\033[46m";
66/* 47 set white background */
67constexpr const char *BG_WHITE = "\033[47m";
68/* 49 set default background color */
69constexpr const char *BG_DEFAULT = "\033[49m";
70
72struct M_EXPORT Color
73{
75 FG = 0,
77 } kind;
78 unsigned color;
79
80 explicit Color(color_kind kind, unsigned color) : kind(kind), color(color) { }
81
82 friend std::ostream & operator<<(std::ostream &out, Color c) {
83 return out << "\033[" << (c.kind ? 48u : 38u) << ";5;" << c.color << "m";
84 }
85};
86
88inline Color fg(unsigned color) { return Color(Color::FG, color); }
90inline Color bg(unsigned color) { return Color(Color::BG, color); }
91
93bool M_EXPORT has_color();
94
95}
constexpr const char * ITALIC
Definition: terminal.hpp:18
constexpr const char * DOUBLE_UNDERLINE
Definition: terminal.hpp:27
constexpr const char * FG_BLUE
Definition: terminal.hpp:45
constexpr const char * BOLD
Definition: terminal.hpp:14
constexpr const char * BG_BLUE
Definition: terminal.hpp:61
constexpr const char * BG_RED
Definition: terminal.hpp:55
constexpr const char * FG_YELLOW
Definition: terminal.hpp:43
constexpr const char * BG_CYAN
Definition: terminal.hpp:65
constexpr const char * FG_MAGENTA
Definition: terminal.hpp:47
constexpr const char * FG_BLACK
Definition: terminal.hpp:37
constexpr const char * BLINK
Definition: terminal.hpp:23
constexpr const char * BG_YELLOW
Definition: terminal.hpp:59
constexpr const char * REVERSE_OFF
Definition: terminal.hpp:35
constexpr const char * UNDERLINE
Definition: terminal.hpp:21
constexpr const char * HALF_BRIGHT
Definition: terminal.hpp:16
constexpr const char * RESET
Definition: terminal.hpp:12
constexpr const char * BG_BLACK
Definition: terminal.hpp:53
constexpr const char * NORMAL
Definition: terminal.hpp:29
constexpr const char * FG_WHITE
Definition: terminal.hpp:51
constexpr const char * BG_GREEN
Definition: terminal.hpp:57
constexpr const char * FG_CYAN
Definition: terminal.hpp:49
constexpr const char * REVERSE
Definition: terminal.hpp:25
constexpr const char * BLINK_OFF
Definition: terminal.hpp:33
constexpr const char * BG_WHITE
Definition: terminal.hpp:67
Color bg(unsigned color)
Create a background color to be printed in a terminal.
Definition: terminal.hpp:90
bool M_EXPORT has_color()
Returns true if the terminal is known to support colors, false otherwise.
Definition: terminal.cpp:7
constexpr const char * UNDERLINE_OFF
Definition: terminal.hpp:31
Color fg(unsigned color)
Create a foreground color to be printed in a terminal.
Definition: terminal.hpp:88
constexpr const char * BG_MAGENTA
Definition: terminal.hpp:63
constexpr const char * FG_GREEN
Definition: terminal.hpp:41
constexpr const char * BG_DEFAULT
Definition: terminal.hpp:69
constexpr const char * FG_RED
Definition: terminal.hpp:39
Wrapper class to ease the use of terminal colors (foreground and background).
Definition: terminal.hpp:73
friend std::ostream & operator<<(std::ostream &out, Color c)
Definition: terminal.hpp:82
Color(color_kind kind, unsigned color)
Definition: terminal.hpp:80
enum m::term::Color::color_kind kind
unsigned color
Definition: terminal.hpp:78