28 static const std::vector<std::string_view> color_support_term{
50 for (
auto term : color_support_term) {
51 if (*vars.TERM == term) {
58 if (*vars.COLORTERM ==
"truecolor") {
61 if (*vars.COLORTERM ==
"24bit") {
74 if (term_support_color(vars)) {
80 bool has_envvar_nocolor = bool(vars.NO_COLOR);
81 bool has_envvar_color = bool(vars.CLICOLOR_FORCE);
83 if (has_envvar_color && has_envvar_nocolor) {
85 "one can not set both NO_COLOR and CLICOLOR_FORCE",
86 std::source_location::current());
89 if (has_envvar_nocolor) {
93 if (has_envvar_color) {
97 auto &res = vars.COLUMN;
102 int val = std::stoi(std::string(*res));
107 }
catch (
const std::invalid_argument &a) {
108 throw error_callback(
109 "Error : COLUMN is not an integer", std::source_location::current());
110 }
catch (
const std::out_of_range &a) {
111 throw error_callback(
112 "Error : COLUMN is out of range", std::source_location::current());
Terminal color escape sequences and enable/disable control.
void enable_colors()
Enable terminal color output.
void disable_colors()
Disable all terminal color output.
std::function< std::invalid_argument(const char *what, std::source_location where)> term_parse_callback_t
Callback signature for parsing error reporting (returns what, receives source location).
Environment variable parsing for terminal color and size configuration (TERM, COLORTERM,...
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.
Holds optional terminal environment variables (TERM, COLORTERM, NO_COLOR, CLICOLOR_FORCE,...
This file contains tty info getters.
void set_tty_columns(int columns)
Set the forced width of the terminal.