From 97b943c832dd3389b81c0896826977e0c447de28 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 12 Nov 2015 21:49:04 -0800 Subject: pass support --- src/emscripten-optimizer/colors.h | 48 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'src/emscripten-optimizer/colors.h') diff --git a/src/emscripten-optimizer/colors.h b/src/emscripten-optimizer/colors.h index 96a7baf29..1746f7e79 100644 --- a/src/emscripten-optimizer/colors.h +++ b/src/emscripten-optimizer/colors.h @@ -2,63 +2,59 @@ #include #include -struct Colors { - static bool use; +namespace Colors { + inline bool use() { + return (getenv("COLORS") && getenv("COLORS")[0] == '1') || // forced + (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit + } - static void normal(std::ostream& stream) { - if (!use) return; + inline 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; + inline 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; + inline 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; + inline 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; + inline 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; + inline 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; + inline 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; + inline 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; +}; -- cgit v1.2.3