Skip to content

Commit

Permalink
libutil/terminal: cache isTTY()
Browse files Browse the repository at this point in the history
  • Loading branch information
intelfx committed Mar 2, 2024
1 parent 8c1eeb4 commit c6f0407
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libutil/terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ namespace nix {

bool isTTY()
{
return isatty(STDERR_FILENO)
static const bool tty =
isatty(STDERR_FILENO)
&& getEnv("TERM").value_or("dumb") != "dumb"
&& !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value());

return tty;
}

std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int width)
Expand Down

0 comments on commit c6f0407

Please sign in to comment.