mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-12-24 06:07:46 +00:00
heed NO_COLOR environment variable
This commit is contained in:
parent
d9b765a3af
commit
6c38c21dfd
2 changed files with 18 additions and 0 deletions
|
@ -338,11 +338,21 @@ bool is_stdout_a_tty()
|
||||||
return is_a_tty.load(std::memory_order_relaxed);
|
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)
|
void set_console_color(int color, bool bright)
|
||||||
{
|
{
|
||||||
if (!is_stdout_a_tty())
|
if (!is_stdout_a_tty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (is_nocolor())
|
||||||
|
return;
|
||||||
|
|
||||||
switch(color)
|
switch(color)
|
||||||
{
|
{
|
||||||
case console_color_default:
|
case console_color_default:
|
||||||
|
@ -461,6 +471,9 @@ void reset_console_color() {
|
||||||
if (!is_stdout_a_tty())
|
if (!is_stdout_a_tty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (is_nocolor())
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||||
|
|
5
external/easylogging++/easylogging++.cc
vendored
5
external/easylogging++/easylogging++.cc
vendored
|
@ -149,6 +149,11 @@ static el::Color colorFromLevel(el::Level level)
|
||||||
|
|
||||||
static void setConsoleColor(el::Color color, bool bright)
|
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
|
#if ELPP_OS_WINDOWS
|
||||||
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
switch (color)
|
switch (color)
|
||||||
|
|
Loading…
Reference in a new issue