summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer
diff options
context:
space:
mode:
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r--src/emscripten-optimizer/colors.h48
1 files changed, 22 insertions, 26 deletions
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 <cstdlib>
#include <ostream>
-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;
+};