36 auto term_parse_error_callback(
const char *what, std::source_location where)
37 -> std::invalid_argument {
58 "LC_CTYPE",
"Character classification locale, used to detect UTF-8 support");
80 bool has_opt_nocolor =
has_option(
"--nocolor");
83 if (has_opt_color && has_opt_nocolor) {
85 "You can not pass --nocolor and --color simultaneously");
105 .COLORTERM = COLORTERM,
106 .NO_COLOR = NO_COLOR,
107 .CLICOLOR_FORCE = CLICOLOR_FORCE,
111 .lc_ctype = lc_ctype,
113 .FORCE_UTF8 = FORCE_UTF8,
115 term_parse_error_callback);
117 if (has_opt_nocolor) {
119 }
else if (has_opt_color) {
151 const char *color_level_str =
"unknown";
Terminal color escape sequences and enable/disable control.
@ TrueColor
24-bit RGB truecolor, \x1b[38;2;r;g;bm.
@ 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.
ColorLevel color_level()
Query the currently detected/forced terminal color support level.
This header file contains utility functions related to exception handling in the code.
This file handler generic cli & env options.
void println(std::string_view sv)
Prints a string to the console followed by a newline.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace for cli utilities
void process_cmdopt_generic_opts()
Process generic cli and env variables options.
bool has_option(const std::string_view &option_name)
Check if an option is present.
void register_cmdopt_generic_opts()
Register generic cli and env variables options.
void process_env_vars()
Detect if the current process should use colored output or not.
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
std::optional< std::string_view > getenv_str_view(const char *env_var)
Get the content of the environment variable if it exist.
void register_opt(std::string name, std::optional< std::string > args, std::string description)
Register a command line option.
void print_help()
Print the help message.
Environment variable parsing for terminal color, size and UTF-8 support configuration (TERM,...
void parse_terminal_support(TermEnvVars vars, const term_parse_callback_t &error_callback)
Parses terminal environment variables to determine color support and set terminal size.
provide information about the source location
bool colors_enabled()
Are colors enabled.
void disable_colors()
Disable all colors.
void enable_colors()
Enable colors in logs.
This file contains tty info getters.
int get_tty_columns()
Get the number of columns of the current terminal.
bool support_utf8()
Query whether the current terminal/locale supports UTF-8 output.
int get_tty_lines()
Get the number of lines of the current terminal.
bool is_a_tty()
Test if current terminal is a tty.