diff --git a/lib/color.cpp b/lib/color.cpp index 6212a06fe3d..c7e1df244f5 100644 --- a/lib/color.cpp +++ b/lib/color.cpp @@ -21,6 +21,7 @@ #ifndef _WIN32 #include #include +#include #include #include #endif @@ -38,12 +39,19 @@ static bool isStreamATty(const std::ostream & os) return stderr_tty; return (stdout_tty && stderr_tty); } + +static bool isCliColorForced() +{ + // See https://bixense.com/clicolors/ + static const bool force_color = (nullptr != getenv("CLICOLOR_FORCE")); + return force_color; +} #endif std::ostream& operator<<(std::ostream & os, Color c) { #ifndef _WIN32 - if (!gDisableColors && isStreamATty(os)) + if (!gDisableColors && (isCliColorForced() || isStreamATty(os))) return os << "\033[" << static_cast(c) << "m"; #else (void)c;