RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1
8
#ifndef RUSH_COLOR_HPP
9
#define RUSH_COLOR_HPP
10
11
#include <cstdint>
12
#include <ostream>
13
#include <string>
14
#include <type_traits>
15
16
namespace
rush::color {
17
23
enum class
Foreground
: std::uint8_t {
24
black = 30,
25
red,
26
green,
27
yellow,
28
blue,
29
magenta,
30
cyan,
31
gray,
32
white = 0
33
};
34
40
enum class
Background
: std::uint8_t {
41
black = 40,
42
red,
43
green,
44
yellow,
45
blue,
46
magenta,
47
cyan,
48
gray
49
};
50
56
enum class
Style
: std::uint8_t {
57
bold = 1,
58
dim,
59
italic,
60
underline,
61
blink,
62
rblink,
63
reversed,
64
conceal,
65
crossed
66
};
67
68
constexpr
char
reset
[] =
"\033[0m"
;
69
constexpr
char
endl
[] =
"\033[0m\n"
;
70
71
using
fg
=
Foreground
;
72
using
bg
=
Background
;
73
using
st
=
Style
;
74
76
template
<
typename
T>
77
using
checkType = std::enable_if_t<std::is_same_v<T, Style> || std::is_same_v<T, Foreground> || std::is_same_v<T, Background>, std::ostream &>;
78
79
inline
std::string escape_sequence(
int
x) {
80
return
static_cast<
std::string
>
(
"\033["
) + std::to_string(x) +
static_cast<
std::string
>
(
"m"
);
81
}
83
94
template
<
typename
T>
95
checkType<T> operator<<(std::ostream &os,
const
T x) {
96
os << escape_sequence(static_cast<int>(x));
97
return
os;
98
}
99
100
}
// namespace rush::color
101
102
#endif
// RUSH_COLOR_HPP
rush::color::fg
Foreground fg
Definition
color.hpp:71
rush::color::bg
Background bg
Definition
color.hpp:72
rush::color::Background
Background
Stream buffer background color.
Definition
color.hpp:40
rush::color::st
Style st
Definition
color.hpp:73
rush::color::endl
constexpr char endl[]
Definition
color.hpp:69
rush::color::Style
Style
Stream buffer style.
Definition
color.hpp:56
rush::color::reset
constexpr char reset[]
Definition
color.hpp:68
rush::color::Foreground
Foreground
Stream buffer foreground color.
Definition
color.hpp:23
include
rush
color.hpp
Generated by
1.17.0