From 6c8d6be6b5b4fc38a3efd9b3ebf9e813c2546d19 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:02:37 +0300 Subject: [PATCH] fix(libutil/terminal): require both stderr/stdout to be tty to output color This is a bit more conservative and safe for cli composability. A common use-case for nix cli is to filter/transform output with grep/ripgrep/jq from stdout. Those tools usually have their own colored output. It's best not to step on their toes. Once example of such command is: `nix registry list | rg nixpkgs` Note that this is more of a band-aid solution. Nix generally handles ANSI colors in an ad-hoc way and there might be some other unexpected bugs related to control characters. --- src/libutil/terminal.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libutil/terminal.cc b/src/libutil/terminal.cc index 4c127ddb078..8b773eaad8c 100644 --- a/src/libutil/terminal.cc +++ b/src/libutil/terminal.cc @@ -18,6 +18,7 @@ bool isTTY() { static const bool tty = isatty(STDERR_FILENO) + && isatty(STDOUT_FILENO) && getEnv("TERM").value_or("dumb") != "dumb" && !(getEnv("NO_COLOR").has_value() || getEnv("NOCOLOR").has_value());