diff options
author | luigi1111 <luigi1111w@gmail.com> | 2023-02-06 12:26:02 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2023-02-06 12:26:02 -0500 |
commit | c12bc6230640ed6004a06e4ba53cdf4999ad80fb (patch) | |
tree | 6173314a2d1b3fee983ba74981bcd7aadfd867eb | |
parent | Merge pull request #8692 (diff) | |
parent | heed NO_COLOR environment variable (diff) | |
download | monero-c12bc6230640ed6004a06e4ba53cdf4999ad80fb.tar.xz |
Merge pull request #8693
bfd7c00 heed NO_COLOR environment variable (moneromooo-monero)
-rw-r--r-- | contrib/epee/src/mlog.cpp | 13 | ||||
-rw-r--r-- | external/easylogging++/easylogging++.cc | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index 092d41777..4ca1a3632 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -338,11 +338,21 @@ bool is_stdout_a_tty() return is_a_tty.load(std::memory_order_relaxed); } +static bool is_nocolor() +{ + static const char *no_color_var = getenv("NO_COLOR"); + static const bool no_color = no_color_var && *no_color_var; // apparently, NO_COLOR=0 means no color too (as per no-color.org) + return no_color; +} + void set_console_color(int color, bool bright) { if (!is_stdout_a_tty()) return; + if (is_nocolor()) + return; + switch(color) { case console_color_default: @@ -461,6 +471,9 @@ void reset_console_color() { if (!is_stdout_a_tty()) return; + if (is_nocolor()) + return; + #ifdef WIN32 HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); diff --git a/external/easylogging++/easylogging++.cc b/external/easylogging++/easylogging++.cc index a765ee8cc..891936b6b 100644 --- a/external/easylogging++/easylogging++.cc +++ b/external/easylogging++/easylogging++.cc @@ -149,6 +149,11 @@ static el::Color colorFromLevel(el::Level level) static void setConsoleColor(el::Color color, bool bright) { + static const char *no_color_var = getenv("NO_COLOR"); + static const bool no_color = no_color_var && *no_color_var; // apparently, NO_COLOR=0 means no color too (as per no-color.org) + if (no_color) + return; + #if ELPP_OS_WINDOWS HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE); switch (color) |