summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Scheidecker <andrew@scheidecker.net>2015-12-23 13:18:42 -0800
committerAndrew Scheidecker <andrew@scheidecker.net>2015-12-23 13:18:42 -0800
commit24c5e1807f583ecc5b6fdeb87eeba2c501f0bac4 (patch)
treebbf5731237f5e249f430b60c9a6213699e3f74ad
parent65f8f24c7bb1da884eb74d5fd742fcf35526483c (diff)
downloadbinaryen-24c5e1807f583ecc5b6fdeb87eeba2c501f0bac4.tar.gz
binaryen-24c5e1807f583ecc5b6fdeb87eeba2c501f0bac4.tar.bz2
binaryen-24c5e1807f583ecc5b6fdeb87eeba2c501f0bac4.zip
Change colors.h to isolate and minimize code that isn't compiled on all platforms
-rw-r--r--src/emscripten-optimizer/colors.h84
1 files changed, 19 insertions, 65 deletions
diff --git a/src/emscripten-optimizer/colors.h b/src/emscripten-optimizer/colors.h
index 9a8cb8ad6..bd12f0c6b 100644
--- a/src/emscripten-optimizer/colors.h
+++ b/src/emscripten-optimizer/colors.h
@@ -17,78 +17,32 @@
#ifndef wasm_color_h
#define wasm_color_h
-#ifndef WIN32
-#include <unistd.h>
#include <cstdlib>
#include <ostream>
-namespace Colors {
- inline bool use() {
- return (getenv("COLORS") && getenv("COLORS")[0] == '1') || // forced
- (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit
- }
-
- inline void normal(std::ostream& stream) {
- if (!use()) return;
#if defined(__linux__) || defined(__apple__)
- stream << "\033[0m";
-#endif
- }
- inline void red(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[31m";
-#endif
- }
- inline void magenta(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[35m";
-#endif
- }
- inline void orange(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[33m";
-#endif
- }
- inline void grey(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[37m";
-#endif
- }
- inline void green(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[32m";
-#endif
- }
- inline void blue(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[34m";
-#endif
- }
- inline void bold(std::ostream& stream) {
- if (!use()) return;
-#if defined(__linux__) || defined(__apple__)
- stream << "\033[1m";
-#endif
+#include <unistd.h>
+
+namespace Colors {
+ inline void outputColorCode(std::ostream& stream,const char* colorCode) {
+ if((getenv("COLORS") && getenv("COLORS")[0] == '1') || // forced
+ (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0'))) { // implicit
+ stream << colorCode;
+ }
}
-};
#else
namespace Colors {
- inline bool use() { return false; }
- inline void normal(std::ostream& stream) {}
- inline void red(std::ostream& stream) {}
- inline void magenta(std::ostream& stream) {}
- inline void orange(std::ostream& stream) {}
- inline void grey(std::ostream& stream) {}
- inline void green(std::ostream& stream) {}
- inline void blue(std::ostream& stream) {}
- inline void bold(std::ostream& stream) {}
-};
+ inline void outputColorCode(std::ostream& stream,const char* colorCode) {}
#endif
+ inline void normal(std::ostream& stream) { outputColorCode(stream,"\033[0m"); }
+ inline void red(std::ostream& stream) { outputColorCode(stream,"\033[31m"); }
+ inline void magenta(std::ostream& stream) { outputColorCode(stream,"\033[35m"); }
+ inline void orange(std::ostream& stream) { outputColorCode(stream,"\033[33m"); }
+ inline void grey(std::ostream& stream) { outputColorCode(stream,"\033[37m"); }
+ inline void green(std::ostream& stream) { outputColorCode(stream,"\033[32m"); }
+ inline void blue(std::ostream& stream) { outputColorCode(stream,"\033[34m"); }
+ inline void bold(std::ostream& stream) { outputColorCode(stream,"\033[1m"); }
+};
+
#endif // wasm_color_h