Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
PrintColor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <string_format.h>
4
5
#include <cstdint>
6
#include <iostream>
7
#include <string>
8
#include <string_view>
9
10
namespace
SpecsCpp::Colors
{
11
12
// TODO this shouldn't use the ANSI escape codes on Windows
13
enum class
Color
{
14
None
= 0,
15
Black
= 30,
16
Red
= 31,
17
Green
= 32,
18
Yellow
= 33,
19
Blue
= 34,
20
Purple
= 35,
21
Cyan
= 36,
22
LightGray
= 37,
23
DarkGray
= 90,
24
LightRed
= 91,
25
LightGreen
= 92,
26
LightYellow
= 93,
27
LightBlue
= 94,
28
LightPurple
= 95,
29
LightCyan
= 96,
30
White
= 97
31
};
32
33
namespace
Unix {
34
enum class
Style
: uint8_t {
35
Normal
= 0,
36
Bold
= 1,
37
Dim
= 2,
38
Italic
= 3,
39
Underline
= 4,
40
SlowBlink
= 5,
41
RapidBlink
= 6,
42
Inverted
= 7,
43
Conceal
= 8,
44
CrossedOut
= 9
45
};
46
47
enum class
ForegroundColor
: uint8_t {
48
Black
= 30,
49
Red
= 31,
50
Green
= 32,
51
Yellow
= 33,
52
Blue
= 34,
53
Purple
= 35,
54
Cyan
= 36,
55
LightGray
= 37,
56
DarkGray
= 90,
57
LightRed
= 91,
58
LightGreen
= 92,
59
LightYellow
= 93,
60
LightBlue
= 94,
61
LightPurple
= 95,
62
LightCyan
= 96,
63
White
= 97
64
};
65
66
enum class
BackgroundColor
: uint8_t {
67
Black
= 40,
68
Red
= 41,
69
Green
= 42,
70
Yellow
= 43,
71
Blue
= 44,
72
Purple
= 45,
73
Cyan
= 46,
74
LightGray
= 47,
75
DarkGray
= 100,
76
LightRed
= 101,
77
LightGreen
= 102,
78
LightYellow
= 103,
79
LightBlue
= 104,
80
LightPurple
= 105,
81
LightCyan
= 106,
82
White
= 107
83
};
84
}
85
86
inline
void
PrintColor
(
87
std::string_view text,
Color
foreground =
Color::None
,
Color
background =
Color::None
,
88
Unix::Style
style =
Unix::Style::Normal
89
) {
90
using namespace
Unix;
91
92
std::string output =
"\033["
;
93
94
if
(style != Style::Normal) output += std::to_string(
static_cast<
std::uint8_t
>
(style));
95
96
if
(foreground !=
Color::None
) {
97
if
(style != Style::Normal) output +=
";"
;
98
output += std::to_string(
static_cast<
std::uint8_t
>
(foreground));
99
}
100
101
if
(background !=
Color::None
) {
102
if
(style != Style::Normal || foreground !=
Color::None
) output +=
";"
;
103
output += std::to_string(
static_cast<
std::uint8_t
>
(background));
104
}
105
106
output += string_format(
"m{}\033[0m"
, text);
107
108
std::cout << output;
109
}
110
111
}
SpecsCpp::Colors::Unix::BackgroundColor
BackgroundColor
Definition
PrintColor.h:66
SpecsCpp::Colors::Unix::ForegroundColor
ForegroundColor
Definition
PrintColor.h:47
SpecsCpp::Colors::Unix::ForegroundColor::Cyan
@ Cyan
SpecsCpp::Colors::Unix::ForegroundColor::White
@ White
SpecsCpp::Colors::Unix::ForegroundColor::LightBlue
@ LightBlue
SpecsCpp::Colors::Unix::ForegroundColor::Yellow
@ Yellow
SpecsCpp::Colors::Unix::ForegroundColor::LightGreen
@ LightGreen
SpecsCpp::Colors::Unix::ForegroundColor::DarkGray
@ DarkGray
SpecsCpp::Colors::Unix::ForegroundColor::Blue
@ Blue
SpecsCpp::Colors::Unix::ForegroundColor::Purple
@ Purple
SpecsCpp::Colors::Unix::ForegroundColor::LightCyan
@ LightCyan
SpecsCpp::Colors::Unix::ForegroundColor::Green
@ Green
SpecsCpp::Colors::Unix::ForegroundColor::Black
@ Black
SpecsCpp::Colors::Unix::ForegroundColor::Red
@ Red
SpecsCpp::Colors::Unix::ForegroundColor::LightRed
@ LightRed
SpecsCpp::Colors::Unix::ForegroundColor::LightYellow
@ LightYellow
SpecsCpp::Colors::Unix::ForegroundColor::LightGray
@ LightGray
SpecsCpp::Colors::Unix::ForegroundColor::LightPurple
@ LightPurple
SpecsCpp::Colors::Unix::Style
Style
Definition
PrintColor.h:34
SpecsCpp::Colors::Unix::Style::RapidBlink
@ RapidBlink
SpecsCpp::Colors::Unix::Style::Bold
@ Bold
SpecsCpp::Colors::Unix::Style::Italic
@ Italic
SpecsCpp::Colors::Unix::Style::SlowBlink
@ SlowBlink
SpecsCpp::Colors::Unix::Style::CrossedOut
@ CrossedOut
SpecsCpp::Colors::Unix::Style::Underline
@ Underline
SpecsCpp::Colors::Unix::Style::Dim
@ Dim
SpecsCpp::Colors::Unix::Style::Conceal
@ Conceal
SpecsCpp::Colors::Unix::Style::Normal
@ Normal
SpecsCpp::Colors::Unix::Style::Inverted
@ Inverted
SpecsCpp::Colors
Definition
PrintColor.h:10
SpecsCpp::Colors::PrintColor
void PrintColor(std::string_view text, Color foreground=Color::None, Color background=Color::None, Unix::Style style=Unix::Style::Normal)
Definition
PrintColor.h:86
SpecsCpp::Colors::Color
Color
Definition
PrintColor.h:13
SpecsCpp::Colors::Color::Cyan
@ Cyan
SpecsCpp::Colors::Color::White
@ White
SpecsCpp::Colors::Color::LightBlue
@ LightBlue
SpecsCpp::Colors::Color::Yellow
@ Yellow
SpecsCpp::Colors::Color::None
@ None
SpecsCpp::Colors::Color::LightGreen
@ LightGreen
SpecsCpp::Colors::Color::DarkGray
@ DarkGray
SpecsCpp::Colors::Color::Blue
@ Blue
SpecsCpp::Colors::Color::Purple
@ Purple
SpecsCpp::Colors::Color::LightCyan
@ LightCyan
SpecsCpp::Colors::Color::Green
@ Green
SpecsCpp::Colors::Color::Black
@ Black
SpecsCpp::Colors::Color::Red
@ Red
SpecsCpp::Colors::Color::LightRed
@ LightRed
SpecsCpp::Colors::Color::LightYellow
@ LightYellow
SpecsCpp::Colors::Color::LightGray
@ LightGray
SpecsCpp::Colors::Color::LightPurple
@ LightPurple
Specs.Reporters
include
Specs
Utilities
PrintColor.h
<3 Mrowr Purr