31static const std::vector<std::string_view> color_suport_term{
54 for (
auto term : color_suport_term) {
55 if (*term_var == term) {
63 if (*colorterm_var ==
"truecolor") {
66 if (*colorterm_var ==
"24bit") {
105 bool has_opt_nocolor =
has_option(
"--nocolor");
108 bool has_envvar_nocolor = bool(
getenv_str(
"NO_COLOR"));
109 bool has_envvar_color = bool(
getenv_str(
"CLICOLOR_FORCE"));
111 if (has_opt_color && has_opt_nocolor) {
113 "You can not pass --nocolor and --color simultaneously");
116 if (has_opt_nocolor) {
117 shambase::term_colors::disable_colors();
118 }
else if (has_opt_color) {
119 shambase::term_colors::enable_colors();
120 }
else if (has_envvar_nocolor) {
121 shambase::term_colors::disable_colors();
122 }
else if (has_envvar_color) {
123 shambase::term_colors::enable_colors();
126 shambase::term_colors::enable_colors();
128 shambase::term_colors::disable_colors();
148 int val = std::stoi(*res);
153 }
catch (
const std::invalid_argument &a) {
156 }
catch (
const std::out_of_range &a) {
178 if (shambase::term_colors::colors_enabled()) {
This header file contains utility functions related to exception handling in the code.
bool term_support_color()
detect if terminal emulator support colored outputs
This file handler generic cli & env options.
void println(std::string_view sv)
Prints a string to the console followed by a newline.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for cli utilities
std::optional< std::string > getenv_str(const char *env_var)
Get the content of the environment variable if it exist.
void process_cmdopt_generic_opts()
Process generic cli and env variables options.
void set_tty_columns(u32 columns)
Set the forced width of the terminal.
bool has_option(const std::string_view &option_name)
Check if an option is present.
bool is_a_tty()
Test if current terminal is a tty.
void process_colors()
Detect if the current process should use colored output or not.
void process_tty()
Process the SHAMTTYCOL environment variable to set the number of columns for the terminal.
void register_cmdopt_generic_opts()
Register generic cli and env variables options.
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
u32 get_tty_lines()
Get the number of lines of the current terminal.
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.
u32 get_tty_columns()
Get the number of columns of the current terminal.
This file contains tty info getters.