13 #include <zypp-tui/Application> 21 { return ::getenv(
"NO_COLOR"); }
29 return Application::instance().config().do_ttyout;
34 return Application::instance().config().do_colors;
39 constexpr
auto detectAnsiEscapes = [](){
40 if ( ::isatty(STDOUT_FILENO) )
42 char *term = ::getenv(
"TERM");
43 if ( term && ::strcmp( term,
"dumb" ) )
49 static bool mayUse = detectAnsiEscapes();
60 const EscapeSequence
clearLN (
"\033[2K\r",
"\n" );
61 const EscapeSequence
cursorUP (
"\033[1A" );
70 static const std::map<std::string, ansi::Color> _def = {
89 if ( colorName.empty() )
103 name_r.erase( 0, 6 );
107 auto && it = _def.find( name_r );
108 if ( it == _def.end() )
110 ERR <<
"Unknown color name '" << name_r <<
"'" << std::endl;
115 ret = ( it->second < ret );
127 const ztui::Config & conf( Application::instance().config() );
ansi::Color color_promptOption
static Color nocolor()
Leave everything unchanged.
Namespace intended to collect all environment variables we use.
ansi::Color color_msgStatus
ansi::Color customColorCtor(ColorContext ctxt_r)
ansi::Color color_lowlight
bool do_colors()
If output is done in colors (depends on config)
const EscapeSequence cursorRIGHT
Cursor right 1 char.
static Color fromString(const std::string &colorName)
ansi::Color color_msgError
ansi::Color color_positive
Various ways to define ansi SGR sequences.
ansi::Color color_osdebug
bool do_ttyout()
True unless output is a dumb tty or file.
bool hasANSIColor()
Simple check whether stdout can handle colors.
const EscapeSequence cursorUP
Cursor up 1 line.
ansi::Color color_highlight
std::string toLower(const std::string &s)
Return lowercase version of s.
bool mayUseANSIEscapes()
Simple check whether stdout is a (not dumb) tty.
const EscapeSequence cursorLEFT
Cursor left 1 char.
ansi::Color color_negative
const EscapeSequence cursorDOWN
Cursor down 1 line.
const EscapeSequence clearLN
Clear entire line.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
ansi::Color color_msgWarning