Merge pull request #1768 from dominicpoeschko/colorterminal_detection

Changed is_color_terminal to be more generic.
This commit is contained in:
Gabi Melman 2020-12-20 03:01:42 +02:00 committed by GitHub
commit adcfb7fb55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -397,17 +397,26 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
#ifdef _WIN32 #ifdef _WIN32
return true; return true;
#else #else
static constexpr std::array<const char *, 14> terms = {
{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}};
const char *env_p = std::getenv("TERM"); static const bool result = []() {
if (env_p == nullptr) const char *env_colorterm_p = std::getenv("COLORTERM");
if (env_colorterm_p != nullptr)
{
return true;
}
static constexpr std::array<const char *, 15> terms = {{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux",
"msys", "putty", "rxvt", "screen", "vt100", "xterm", "alacritty"}};
const char *env_term_p = std::getenv("TERM");
if (env_term_p == nullptr)
{ {
return false; return false;
} }
static const bool result = return std::any_of(terms.begin(), terms.end(), [&](const char *term) { return std::strstr(env_term_p, term) != nullptr; });
std::any_of(terms.begin(), terms.end(), [&](const char *term) { return std::strstr(env_p, term) != nullptr; }); }();
return result; return result;
#endif #endif
} }