Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
color.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16
17#include <sham/term/color.hpp>
18
19#define TERM_ESCAPTE_CHAR "\x1b["
20namespace {
21 bool colors_enabled = true;
22
23 const char *_empty_str = "";
24 const char *_esc_char = TERM_ESCAPTE_CHAR;
25 const char *_reset = TERM_ESCAPTE_CHAR "0m";
26 const char *_bold = TERM_ESCAPTE_CHAR "1m";
27 const char *_faint = TERM_ESCAPTE_CHAR "2m";
28 const char *_underline = TERM_ESCAPTE_CHAR "4m";
29 const char *_blink = TERM_ESCAPTE_CHAR "5m";
30 const char *_col8b_black = TERM_ESCAPTE_CHAR "30m";
31 const char *_col8b_red = TERM_ESCAPTE_CHAR "31m";
32 const char *_col8b_green = TERM_ESCAPTE_CHAR "32m";
33 const char *_col8b_yellow = TERM_ESCAPTE_CHAR "33m";
34 const char *_col8b_blue = TERM_ESCAPTE_CHAR "34m";
35 const char *_col8b_magenta = TERM_ESCAPTE_CHAR "35m";
36 const char *_col8b_cyan = TERM_ESCAPTE_CHAR "36m";
37 const char *_col8b_white = TERM_ESCAPTE_CHAR "37m";
38} // namespace
39
40namespace sham::term {
41
42 namespace style {
43 const char *reset() { return (colors_enabled) ? _reset : _empty_str; }
44 const char *bold() { return (colors_enabled) ? _bold : _empty_str; }
45 const char *faint() { return (colors_enabled) ? _faint : _empty_str; }
46 const char *underline() { return (colors_enabled) ? _underline : _empty_str; }
47 const char *blink() { return (colors_enabled) ? _blink : _empty_str; }
48 } // namespace style
49
50 namespace colors_8b {
51 const char *black() { return (colors_enabled) ? _col8b_black : _empty_str; }
52 const char *red() { return (colors_enabled) ? _col8b_red : _empty_str; }
53 const char *green() { return (colors_enabled) ? _col8b_green : _empty_str; }
54 const char *yellow() { return (colors_enabled) ? _col8b_yellow : _empty_str; }
55 const char *blue() { return (colors_enabled) ? _col8b_blue : _empty_str; }
56 const char *magenta() { return (colors_enabled) ? _col8b_magenta : _empty_str; }
57 const char *cyan() { return (colors_enabled) ? _col8b_cyan : _empty_str; }
58 const char *white() { return (colors_enabled) ? _col8b_white : _empty_str; }
59 } // namespace colors_8b
60
62 void enable_colors() { colors_enabled = true; }
63
65 void disable_colors() { colors_enabled = false; }
66
68 bool are_colors_enabled() { return colors_enabled; }
69
70} // namespace sham::term
Terminal color escape sequences and enable/disable control.
void enable_colors()
Enable terminal color output.
Definition color.cpp:62
void disable_colors()
Disable all terminal color output.
Definition color.cpp:65
bool are_colors_enabled()
Query whether terminal color output is currently enabled.
Definition color.cpp:68
const char * red()
Escape sequence to set red text color.
Definition color.cpp:52
const char * green()
Escape sequence to set green text color.
Definition color.cpp:53
const char * black()
Escape sequence to set black text color.
Definition color.cpp:51
const char * white()
Escape sequence to set white text color.
Definition color.cpp:58
const char * magenta()
Escape sequence to set magenta (pink) text color.
Definition color.cpp:56
const char * cyan()
Escape sequence to set cyan text color.
Definition color.cpp:57
const char * blue()
Escape sequence to set blue text color.
Definition color.cpp:55
const char * yellow()
Escape sequence to set yellow text color.
Definition color.cpp:54
Terminal text styling escape sequences (bold, faint, underline, blink, reset).
Definition color.hpp:24
const char * blink()
escape sequence to set blinking text formatting.
Definition color.cpp:47
const char * reset()
escape sequence to reset the terminal text formatting.
Definition color.cpp:43
const char * bold()
escape sequence to set bold text formatting.
Definition color.cpp:44
const char * underline()
escape sequence to set underlined text formatting.
Definition color.cpp:46
const char * faint()
escape sequence to set faint (dim) text formatting.
Definition color.cpp:45
bool colors_enabled()
Are colors enabled.