Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
colors.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
37
38#pragma once
39
40#include <functional>
41#include <ostream>
42
50// RGB Text Colors (8-bit)
51#define RGB_TEXT(r, g, b) "\x1b[38;2;" #r ";" #g ";" #b "m"
52
60// RGB Background Colors (8-bit)
61#define RGB_BG(r, g, b) "\x1b[48;2;" #r ";" #g ";" #b "m"
62
64{
65 using ColorFunc = std::function<std::ostream&(std::ostream&)>;
66
75 bool isTerminal(const std::ostream& stream);
76
85 std::ostream& reset(std::ostream& stream);
86
91 namespace colors
92 {
99 std::ostream& keepOriginal(std::ostream& stream);
100
107 std::ostream& black(std::ostream& stream);
108
115 std::ostream& red(std::ostream& stream);
116
123 std::ostream& green(std::ostream& stream);
124
131 std::ostream& yellow(std::ostream& stream);
132
139 std::ostream& blue(std::ostream& stream);
140
147 std::ostream& magenta(std::ostream& stream);
148
155 std::ostream& cyan(std::ostream& stream);
156
163 std::ostream& white(std::ostream& stream);
164
171 std::ostream& brightBlack(std::ostream& stream);
172
179 std::ostream& brightRed(std::ostream& stream);
180
187 std::ostream& brightGreen(std::ostream& stream);
188
195 std::ostream& brightYellow(std::ostream& stream);
196
203 std::ostream& brightBlue(std::ostream& stream);
204
211 std::ostream& brightMagenta(std::ostream& stream);
212
219 std::ostream& brightCyan(std::ostream& stream);
220
227 std::ostream& brightWhite(std::ostream& stream);
228 } // namespace colors
229
234 namespace colorsBg
235 {
242 std::ostream& brightBlack(std::ostream& stream);
243
250 std::ostream& brightRed(std::ostream& stream);
251
258 std::ostream& brightGreen(std::ostream& stream);
259
266 std::ostream& brightYellow(std::ostream& stream);
267
274 std::ostream& brightBlue(std::ostream& stream);
275
282 std::ostream& brightCyan(std::ostream& stream);
283
290 std::ostream& brightWhite(std::ostream& stream);
291 } // namespace colorsBg
292
297 namespace formats
298 {
305 std::ostream& bold(std::ostream& stream);
306
313 std::ostream& dim(std::ostream& stream);
314
321 std::ostream& underline(std::ostream& stream);
322
329 std::ostream& blink(std::ostream& stream);
330
337 std::ostream& reverse(std::ostream& stream);
338
345 std::ostream& hidden(std::ostream& stream);
346 } // namespace formats
347} // namespace steppable::__internals::utils
A namespace containing functions to set the background color in an output stream.
Definition colors.cpp:214
std::ostream & brightYellow(std::ostream &stream)
Set the background color to bright yellow.
Definition colors.cpp:236
std::ostream & brightGreen(std::ostream &stream)
Set the background color to bright green.
Definition colors.cpp:229
std::ostream & brightWhite(std::ostream &stream)
Set the background color to bright white.
Definition colors.cpp:257
std::ostream & brightBlack(std::ostream &stream)
Set the background color to bright black.
Definition colors.cpp:215
std::ostream & brightBlue(std::ostream &stream)
Set the background color to bright blue.
Definition colors.cpp:243
std::ostream & brightCyan(std::ostream &stream)
Set the background color to bright cyan.
Definition colors.cpp:250
std::ostream & brightRed(std::ostream &stream)
Set the background color to bright red.
Definition colors.cpp:222
A namespace containing functions to set the text color in an output stream.
Definition colors.cpp:93
std::ostream & brightWhite(std::ostream &stream)
Set the text color to bright white.
Definition colors.cpp:205
std::ostream & brightGreen(std::ostream &stream)
Set the text color to bright green.
Definition colors.cpp:170
std::ostream & white(std::ostream &stream)
Set the text color to white.
Definition colors.cpp:149
std::ostream & brightMagenta(std::ostream &stream)
Set the text color to bright magenta.
Definition colors.cpp:191
std::ostream & red(std::ostream &stream)
Set the text color to red.
Definition colors.cpp:107
std::ostream & keepOriginal(std::ostream &stream)
Does nothing.
Definition colors.cpp:94
std::ostream & brightCyan(std::ostream &stream)
Set the text color to bright cyan.
Definition colors.cpp:198
std::ostream & brightYellow(std::ostream &stream)
Set the text color to bright yellow.
Definition colors.cpp:177
std::ostream & brightBlack(std::ostream &stream)
Set the text color to bright black.
Definition colors.cpp:156
std::ostream & blue(std::ostream &stream)
Set the text color to blue.
Definition colors.cpp:128
std::ostream & cyan(std::ostream &stream)
Set the text color to cyan.
Definition colors.cpp:142
std::ostream & magenta(std::ostream &stream)
Set the text color to magenta.
Definition colors.cpp:135
std::ostream & green(std::ostream &stream)
Set the text color to green.
Definition colors.cpp:114
std::ostream & yellow(std::ostream &stream)
Set the text color to yellow.
Definition colors.cpp:121
std::ostream & brightRed(std::ostream &stream)
Set the text color to bright red.
Definition colors.cpp:163
std::ostream & brightBlue(std::ostream &stream)
Set the text color to bright blue.
Definition colors.cpp:184
std::ostream & black(std::ostream &stream)
Set the text color to black.
Definition colors.cpp:100
A namespace containing functions to set the text format in an output stream.
Definition colors.cpp:266
std::ostream & bold(std::ostream &stream)
Set the text format to bold.
Definition colors.cpp:267
std::ostream & hidden(std::ostream &stream)
Set the text format to hidden.
Definition colors.cpp:302
std::ostream & reverse(std::ostream &stream)
Set the text format to reverse.
Definition colors.cpp:295
std::ostream & underline(std::ostream &stream)
Set the text format to underline.
Definition colors.cpp:281
std::ostream & blink(std::ostream &stream)
Set the text format to blink.
Definition colors.cpp:288
std::ostream & dim(std::ostream &stream)
Set the text format to dim.
Definition colors.cpp:274
The namespace containing utility functions for the Steppable library.
Definition argParse.cpp:40
std::ostream & reset(std::ostream &stream)
Reset the text color and format to the default values.
Definition colors.cpp:85
std::function< std::ostream &(std::ostream &)> ColorFunc
Definition colors.hpp:65
bool isTerminal(const std::ostream &stream)
Check if the output stream is a terminal.
Definition colors.cpp:74
Untitled