diff options
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/colors.cpp | 12 | ||||
-rw-r--r-- | src/support/colors.h | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/support/colors.cpp b/src/support/colors.cpp index aca720514..7310427e4 100644 --- a/src/support/colors.cpp +++ b/src/support/colors.cpp @@ -24,15 +24,19 @@ # include <unistd.h> #endif -namespace Colors { -void outputColorCode(std::ostream& stream, const char* colorCode) { +namespace { +bool colors_disabled = false; +} // anonymous namespace + +void Colors::disable() { colors_disabled = true; } + +void Colors::outputColorCode(std::ostream& stream, const char* colorCode) { #if defined(CAN_HAZ_COLOR) const static bool has_color = []() { return (getenv("COLORS") && getenv("COLORS")[0] == '1') || // forced (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit }(); - if (has_color) stream << colorCode; + if (has_color && !colors_disabled) stream << colorCode; #endif } -} // namespace Colors diff --git a/src/support/colors.h b/src/support/colors.h index 03ebb1240..41a39d589 100644 --- a/src/support/colors.h +++ b/src/support/colors.h @@ -20,6 +20,7 @@ #include <iosfwd> namespace Colors { +void disable(); void outputColorCode(std::ostream&stream, const char *colorCode); inline void normal(std::ostream& stream) { outputColorCode(stream,"\033[0m"); } inline void red(std::ostream& stream) { outputColorCode(stream,"\033[31m"); } |