Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
term_colors.hpp
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
10#pragma once
11
19#include <string>
20
27#define TERM_ESCAPTE_CHAR "\x1b["
28
29namespace shambase {
30
31 namespace details {
32
39 struct TermColors {
40 bool colors_on = true;
41
45 std::string reset = TERM_ESCAPTE_CHAR "0m";
47 std::string bold = TERM_ESCAPTE_CHAR "1m";
49 std::string faint = TERM_ESCAPTE_CHAR "2m";
51 std::string underline = TERM_ESCAPTE_CHAR "4m";
53 std::string blink = TERM_ESCAPTE_CHAR "5m";
55 std::string col8b_black = TERM_ESCAPTE_CHAR "30m";
57 std::string col8b_red = TERM_ESCAPTE_CHAR "31m";
59 std::string col8b_green = TERM_ESCAPTE_CHAR "32m";
61 std::string col8b_yellow = TERM_ESCAPTE_CHAR "33m";
63 std::string col8b_blue = TERM_ESCAPTE_CHAR "34m";
65 std::string col8b_magenta = TERM_ESCAPTE_CHAR "35m";
67 std::string col8b_cyan = TERM_ESCAPTE_CHAR "36m";
69 std::string col8b_white = TERM_ESCAPTE_CHAR "37m";
70
75 return {false, "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
76 }
77
81 static TermColors get_config_colors() { return {}; }
82 };
83
92 extern TermColors _int_term_colors;
93
94 } // namespace details
95
96 namespace term_colors {
97
99 void enable_colors();
100
102 void disable_colors();
103
105 inline bool colors_enabled() { return details::_int_term_colors.colors_on; }
106
108 inline const std::string empty() { return ""; };
110 inline const std::string reset() { return details::_int_term_colors.reset; };
112 inline const std::string bold() { return details::_int_term_colors.bold; };
114 inline const std::string faint() { return details::_int_term_colors.faint; };
116 inline const std::string underline() { return details::_int_term_colors.underline; };
118 inline const std::string blink() { return details::_int_term_colors.blink; };
120 inline const std::string col8b_black() { return details::_int_term_colors.col8b_black; };
122 inline const std::string col8b_red() { return details::_int_term_colors.col8b_red; };
124 inline const std::string col8b_green() { return details::_int_term_colors.col8b_green; };
126 inline const std::string col8b_yellow() { return details::_int_term_colors.col8b_yellow; };
128 inline const std::string col8b_blue() { return details::_int_term_colors.col8b_blue; };
130 inline const std::string col8b_magenta() {
131 return details::_int_term_colors.col8b_magenta;
132 };
134 inline const std::string col8b_cyan() { return details::_int_term_colors.col8b_cyan; };
136 inline const std::string col8b_white() { return details::_int_term_colors.col8b_white; };
137
138 } // namespace term_colors
139
140} // namespace shambase
Namespace for internal details of the logs module.
namespace for basic c++ utilities
Struct representing the terminal colors to be used for printing.
std::string col8b_white
Escape sequence to set white text color.
static TermColors get_config_colors()
Returns a TermColors struct with all colors enabled.
std::string col8b_blue
Escape sequence to set blue text color.
bool colors_on
are colors on in this config
std::string col8b_yellow
Escape sequence to set yellow text color.
std::string reset
Escape sequence to reset the terminal text formatting.
std::string esc_char
Escape character for terminal control sequences.
std::string col8b_red
Escape sequence to set red text color.
std::string faint
Escape sequence to set faint (dim) text formatting.
static TermColors get_config_nocolors()
Returns a TermColors struct with all colors disabled.
std::string underline
Escape sequence to set underlined text formatting.
std::string col8b_magenta
Escape sequence to set magenta (pink) text color.
std::string bold
Escape sequence to set bold text formatting.
std::string col8b_black
Escape sequence to set black text color.
std::string col8b_cyan
Escape sequence to set cyan text color.
std::string col8b_green
Escape sequence to set green text color.
std::string blink
Escape sequence to set blinking text formatting.
const std::string reset()
Get the reset terminal escape char.
const std::string col8b_yellow()
Get the yellow terminal escape char.
const std::string col8b_white()
Get the white terminal escape char.
const std::string col8b_magenta()
Get the magenta (pink) terminal escape char.
const std::string empty()
Get the empty terminal escape.
const std::string blink()
Get the blink terminal escape char.
const std::string col8b_green()
Get the green terminal escape char.
const std::string col8b_blue()
Get the blue terminal escape char.
const std::string col8b_black()
Get the black terminal escape char.
const std::string underline()
Get the underline terminal escape char.
bool colors_enabled()
Are colors enabled.
const std::string col8b_cyan()
Get the cyan terminal escape char.
const std::string faint()
Get the faint terminal escape char.
const std::string bold()
Get the bold terminal escape char.
#define TERM_ESCAPTE_CHAR
Escape character for terminal control sequences.
const std::string col8b_red()
Get the red terminal escape char.