RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
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
16namespace rush::color {
17
23enum 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
40enum class Background : std::uint8_t {
41 black = 40,
42 red,
43 green,
44 yellow,
45 blue,
46 magenta,
47 cyan,
48 gray
49};
50
56enum 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
68constexpr char reset[] = "\033[0m";
69constexpr char endl[] = "\033[0m\n";
71using fg = Foreground;
72using bg = Background;
73using st = Style;
76template <typename T>
77using 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
79inline std::string escape_sequence(int x) {
80 return static_cast<std::string>("\033[") + std::to_string(x) + static_cast<std::string>("m");
81}
94template <typename T>
95checkType<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
Background
Stream buffer background color.
Definition color.hpp:40
constexpr char endl[]
Definition color.hpp:69
Style
Stream buffer style.
Definition color.hpp:56
constexpr char reset[]
Definition color.hpp:68
Foreground
Stream buffer foreground color.
Definition color.hpp:23