libutil/terminal: cache isTTY()

This commit is contained in:
Ivan Shapovalov 2024-03-01 23:17:44 +01:00
parent 8c1eeb4681
commit c6f0407103

View file

@ -9,9 +9,12 @@ namespace nix {
bool isTTY() bool isTTY()
{ {
return isatty(STDERR_FILENO) static const bool tty =
isatty(STDERR_FILENO)
&& getEnv("TERM").value_or("dumb") != "dumb" && getEnv("TERM").value_or("dumb") != "dumb"
&& !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value()); && !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value());
return tty;
} }
std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int width) std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int width)