diff options
author | Siddharth <siddu.druid@gmail.com> | 2019-05-17 21:43:50 +0200 |
---|---|---|
committer | Alon Zakai <azakai@google.com> | 2019-05-17 12:43:49 -0700 |
commit | 1184678086b284944bb119a97ca048b64d4078b6 (patch) | |
tree | 1caedfbaa927e2cb03f46feeead9d48b5cdfb55b /src/support | |
parent | 1095ef96673f4f33d76da6d58b0ad65c3c257f76 (diff) | |
download | binaryen-1184678086b284944bb119a97ca048b64d4078b6.tar.gz binaryen-1184678086b284944bb119a97ca048b64d4078b6.tar.bz2 binaryen-1184678086b284944bb119a97ca048b64d4078b6.zip |
Allow color API to enable and disable colors (#2111)
This is useful for front-ends which wish to selectively enable or
disable coloring.
Also expose these APIs from the C API.
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/colors.cpp | 9 | ||||
-rw-r--r-- | src/support/colors.h | 3 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/support/colors.cpp b/src/support/colors.cpp index 6d06b69fd..d8a2c7f52 100644 --- a/src/support/colors.cpp +++ b/src/support/colors.cpp @@ -20,10 +20,11 @@ #include <ostream> namespace { -bool colors_disabled = false; +bool colors_enabled = true; } // anonymous namespace -void Colors::disable() { colors_disabled = true; } +void Colors::setEnabled(bool enabled) { colors_enabled = enabled; } +bool Colors::isEnabled() { return colors_enabled; } #if defined(__linux__) || defined(__APPLE__) #include <unistd.h> @@ -34,7 +35,7 @@ void Colors::outputColorCode(std::ostream& stream, const char* colorCode) { (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit }(); - if (has_color && !colors_disabled) { + if (has_color && colors_enabled) { stream << colorCode; } } @@ -50,7 +51,7 @@ void Colors::outputColorCode(std::ostream& stream, const WORD& colorCode) { }(); static HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); static HANDLE hStderr = GetStdHandle(STD_ERROR_HANDLE); - if (has_color && !colors_disabled) + if (has_color && colors_enabled) SetConsoleTextAttribute(&stream == &std::cout ? hStdout : hStderr, colorCode); } diff --git a/src/support/colors.h b/src/support/colors.h index 68a251969..f2c446025 100644 --- a/src/support/colors.h +++ b/src/support/colors.h @@ -20,7 +20,8 @@ #include <iosfwd> namespace Colors { -void disable(); +void setEnabled(bool enabled); +bool isEnabled(); #if defined(__linux__) || defined(__APPLE__) void outputColorCode(std::ostream& stream, const char* colorCode); |