Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
color.hpp File Reference

Terminal color escape sequences and enable/disable control. More...

#include <cstdint>
#include <string>
Include dependency graph for color.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  sham
 namespace for backends this one is named only sham since shambackends is too long to write
namespace  sham::term::style
 Terminal text styling escape sequences (bold, faint, underline, blink, reset).
namespace  sham::term::colors_8b
 8 bit 8-color palette escape sequences.
namespace  sham::term::colors_256
 256-color palette escape sequences (\x1b[38;5;Nm / \x1b[48;5;Nm).
namespace  sham::term::colors_24b
 24-bit RGB truecolor escape sequences (\x1b[38;2;r;g;bm / \x1b[48;2;r;g;bm).

Enumerations

enum class  sham::term::ColorLevel { NoColor = 0 , Basic = 1 , ANSI256 = 2 , TrueColor = 3 }
 The possible levels of terminal color support. More...

Functions

ColorLevel sham::term::color_level ()
 Query the currently detected/forced terminal color support level.
void sham::term::set_color_level (ColorLevel level)
 Set the terminal color support level.
void sham::term::enable_colors ()
 Enable colors.
void sham::term::disable_colors ()
 Disable all colors.
bool sham::term::are_colors_enabled ()
 Query whether terminal color output is currently enabled.
const char * sham::term::style::reset ()
 escape sequence to reset the terminal text formatting.
const char * sham::term::style::bold ()
 escape sequence to set bold text formatting.
const char * sham::term::style::faint ()
 escape sequence to set faint (dim) text formatting.
const char * sham::term::style::underline ()
 escape sequence to set underlined text formatting.
const char * sham::term::style::blink ()
 escape sequence to set blinking text formatting.
const char * sham::term::colors_8b::black ()
 Escape sequence to set black text color.
const char * sham::term::colors_8b::red ()
 Escape sequence to set red text color.
const char * sham::term::colors_8b::green ()
 Escape sequence to set green text color.
const char * sham::term::colors_8b::yellow ()
 Escape sequence to set yellow text color.
const char * sham::term::colors_8b::blue ()
 Escape sequence to set blue text color.
const char * sham::term::colors_8b::magenta ()
 Escape sequence to set magenta (pink) text color.
const char * sham::term::colors_8b::cyan ()
 Escape sequence to set cyan text color.
const char * sham::term::colors_8b::white ()
 Escape sequence to set white text color.
std::string sham::term::colors_256::foreground (std::uint8_t index)
 Escape sequence to set the given palette index as foreground text color.
std::string sham::term::colors_256::background (std::uint8_t index)
 Escape sequence to set the given palette index as background color.
std::string sham::term::colors_24b::foreground (std::uint8_t r, std::uint8_t g, std::uint8_t b)
 Escape sequence to set the given RGB foreground text color.
std::string sham::term::colors_24b::background (std::uint8_t r, std::uint8_t g, std::uint8_t b)
 Escape sequence to set the given RGB background color.

Detailed Description

Terminal color escape sequences and enable/disable control.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file color.hpp.

Enumeration Type Documentation

◆ ColorLevel

enum class sham::term::ColorLevel
strong

The possible levels of terminal color support.

Enumerator
NoColor 

No color support, plain ASCII output only.

Basic 

ANSI/16 colors (basic SGR codes), \x1b[3Xm.

ANSI256 

256-color palette (16 ANSI + 216-color cube + 24 grayscale), \x1b[38;5;Nm.

TrueColor 

24-bit RGB truecolor, \x1b[38;2;r;g;bm.

Definition at line 27 of file color.hpp.

Function Documentation

◆ are_colors_enabled()

bool sham::term::are_colors_enabled ( )

Query whether terminal color output is currently enabled.

Are colors enabled.

Definition at line 56 of file color.cpp.

◆ color_level()

ColorLevel sham::term::color_level ( )

Query the currently detected/forced terminal color support level.

Definition at line 45 of file color.cpp.

◆ disable_colors()

void sham::term::disable_colors ( )

Disable all colors.

Definition at line 53 of file color.cpp.

◆ enable_colors()

void sham::term::enable_colors ( )

Enable colors.

Enable colors TODO: should set to the result of the color max(color_detect(), Basic)

Definition at line 50 of file color.cpp.

◆ set_color_level()

void sham::term::set_color_level ( ColorLevel level)

Set the terminal color support level.

Parameters
levelthe new color support level

Definition at line 46 of file color.cpp.