diff options
-rw-r--r-- | src/s2wasm-main.cpp | 2 | ||||
-rw-r--r-- | src/support/colors.cpp | 12 | ||||
-rw-r--r-- | src/support/colors.h | 1 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp index a7060dd6e..1940fcb1a 100644 --- a/src/s2wasm-main.cpp +++ b/src/s2wasm-main.cpp @@ -18,6 +18,7 @@ // wasm2asm console tool // +#include "support/colors.h" #include "support/command-line.h" #include "s2wasm.h" @@ -30,6 +31,7 @@ int main(int argc, const char *argv[]) { Options::Arguments::One, [](Options *o, const std::string &argument) { o->extra["output"] = argument; + Colors::disable(); }) .add("--global-base", "-g", "Where to start to place globals", Options::Arguments::One, 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"); } |