diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-04 20:35:58 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-04 20:35:58 -0500 |
commit | 44e07a9ba2c53dfae94b41f9c24acd0d57b4d6bf (patch) | |
tree | 0239683030a0d0b539857a6138f30880ba717cae /src/support | |
parent | aea8cbf812299d85567daf9eaeca4543ede43192 (diff) | |
parent | 908539ab1f4cc54a9511f076ae670457533806a4 (diff) | |
download | binaryen-44e07a9ba2c53dfae94b41f9c24acd0d57b4d6bf.tar.gz binaryen-44e07a9ba2c53dfae94b41f9c24acd0d57b4d6bf.tar.bz2 binaryen-44e07a9ba2c53dfae94b41f9c24acd0d57b4d6bf.zip |
Merge pull request #64 from WebAssembly/color-disable
Disable colors when outputting to a file
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"); } |