diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-09 11:24:06 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-09 11:24:06 -0800 |
commit | 6098d7c270a3b16c4c68dd6996597eae2a74a5f4 (patch) | |
tree | 40132a4df766df171d7541c3278e1506adf07f18 /src/emscripten-optimizer/colors.h | |
parent | 2c6f7cfa8156448e5ce82ebd1a7526b523dfc7f0 (diff) | |
download | binaryen-6098d7c270a3b16c4c68dd6996597eae2a74a5f4.tar.gz binaryen-6098d7c270a3b16c4c68dd6996597eae2a74a5f4.tar.bz2 binaryen-6098d7c270a3b16c4c68dd6996597eae2a74a5f4.zip |
restructure code, put emscripten-optimizer stuff in its own dir
Diffstat (limited to 'src/emscripten-optimizer/colors.h')
-rw-r--r-- | src/emscripten-optimizer/colors.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/emscripten-optimizer/colors.h b/src/emscripten-optimizer/colors.h new file mode 100644 index 000000000..96a7baf29 --- /dev/null +++ b/src/emscripten-optimizer/colors.h @@ -0,0 +1,64 @@ +#include <unistd.h> +#include <cstdlib> +#include <ostream> + +struct Colors { + static bool use; + + static void normal(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[0m"; +#endif + } + static void red(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[31m"; +#endif + } + static void magenta(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[35m"; +#endif + } + static void orange(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[33m"; +#endif + } + static void grey(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[37m"; +#endif + } + static void green(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[32m"; +#endif + } + static void blue(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[34m"; +#endif + } + static void bold(std::ostream& stream) { + if (!use) return; +#if defined(__linux__) || defined(__apple__) + stream << "\033[1m"; +#endif + } + + Colors() { + use = (getenv("COLORS") && getenv("COLORS")[0] == '1') || // forced + (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit + } +} colors; + +bool Colors::use; + |