Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
color.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
18
19#include <cstdint>
20#include <string>
21
22namespace sham::term {
23
27 enum class ColorLevel {
31 Basic = 1,
36 };
37
41 ColorLevel color_level();
42
48 void set_color_level(ColorLevel level);
49
51 void enable_colors();
52
54 void disable_colors();
55
57 bool are_colors_enabled();
58
62 namespace style {
64 const char *reset();
66 const char *bold();
68 const char *faint();
70 const char *underline();
72 const char *blink();
73 } // namespace style
74
78 namespace colors_8b {
80 const char *black();
82 const char *red();
84 const char *green();
86 const char *yellow();
88 const char *blue();
90 const char *magenta();
92 const char *cyan();
94 const char *white();
95 } // namespace colors_8b
96
103 namespace colors_256 {
105 std::string foreground(std::uint8_t index);
107 std::string background(std::uint8_t index);
108 } // namespace colors_256
109
116 namespace colors_24b {
118 std::string foreground(std::uint8_t r, std::uint8_t g, std::uint8_t b);
120 std::string background(std::uint8_t r, std::uint8_t g, std::uint8_t b);
121 } // namespace colors_24b
122
123} // namespace sham::term
ColorLevel
The possible levels of terminal color support.
Definition color.hpp:27
@ TrueColor
24-bit RGB truecolor, \x1b[38;2;r;g;bm.
Definition color.hpp:35
@ NoColor
No color support, plain ASCII output only.
Definition color.hpp:29
@ Basic
ANSI/16 colors (basic SGR codes), \x1b[3Xm.
Definition color.hpp:31
@ ANSI256
256-color palette (16 ANSI + 216-color cube + 24 grayscale), \x1b[38;5;Nm.
Definition color.hpp:33
24-bit RGB truecolor escape sequences (\x1b[38;2;r;g;bm / \x1b[48;2;r;g;bm).
Definition color.hpp:116
std::string foreground(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Escape sequence to set the given RGB foreground text color.
Definition color.cpp:108
std::string background(std::uint8_t r, std::uint8_t g, std::uint8_t b)
Escape sequence to set the given RGB background color.
Definition color.cpp:111
256-color palette escape sequences (\x1b[38;5;Nm / \x1b[48;5;Nm).
Definition color.hpp:103
std::string background(std::uint8_t index)
Escape sequence to set the given palette index as background color.
Definition color.cpp:91
std::string foreground(std::uint8_t index)
Escape sequence to set the given palette index as foreground text color.
Definition color.cpp:90
8 bit 8-color palette escape sequences.
Definition color.hpp:78
const char * red()
Escape sequence to set red text color.
Definition color.cpp:68
const char * green()
Escape sequence to set green text color.
Definition color.cpp:69
const char * black()
Escape sequence to set black text color.
Definition color.cpp:67
const char * white()
Escape sequence to set white text color.
Definition color.cpp:74
const char * magenta()
Escape sequence to set magenta (pink) text color.
Definition color.cpp:72
const char * cyan()
Escape sequence to set cyan text color.
Definition color.cpp:73
const char * blue()
Escape sequence to set blue text color.
Definition color.cpp:71
const char * yellow()
Escape sequence to set yellow text color.
Definition color.cpp:70
Terminal text styling escape sequences (bold, faint, underline, blink, reset).
Definition color.hpp:62
const char * blink()
escape sequence to set blinking text formatting.
Definition color.cpp:63
const char * reset()
escape sequence to reset the terminal text formatting.
Definition color.cpp:59
const char * bold()
escape sequence to set bold text formatting.
Definition color.cpp:60
const char * underline()
escape sequence to set underlined text formatting.
Definition color.cpp:62
const char * faint()
escape sequence to set faint (dim) text formatting.
Definition color.cpp:61