summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-01-04 20:35:58 -0500
committerAlon Zakai <alonzakai@gmail.com>2016-01-04 20:35:58 -0500
commit44e07a9ba2c53dfae94b41f9c24acd0d57b4d6bf (patch)
tree0239683030a0d0b539857a6138f30880ba717cae /src
parentaea8cbf812299d85567daf9eaeca4543ede43192 (diff)
parent908539ab1f4cc54a9511f076ae670457533806a4 (diff)
downloadbinaryen-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')
-rw-r--r--src/s2wasm-main.cpp2
-rw-r--r--src/support/colors.cpp12
-rw-r--r--src/support/colors.h1
3 files changed, 11 insertions, 4 deletions
diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp
index d8faa29f1..278fec693 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 "support/file.h"
#include "s2wasm.h"
@@ -31,6 +32,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"); }