treewide: replace usages of isatty(STDERR_FILENO) with shouldANSI()

This commit is contained in:
Ivan Shapovalov 2024-03-01 23:11:24 +01:00
parent 950b6401f9
commit d9fc4bf5c5
3 changed files with 8 additions and 3 deletions

View file

@ -16,6 +16,7 @@
#include "xml-writer.hh"
#include "legacy.hh"
#include "eval-settings.hh" // for defexpr
#include "terminal.hh"
#include <cerrno>
#include <ctime>
@ -1089,7 +1090,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
return;
}
bool tty = isatty(STDOUT_FILENO);
bool tty = shouldANSI();
RunPager pager;
Table table;

View file

@ -16,6 +16,7 @@
#include "loggers.hh"
#include "markdown.hh"
#include "memory-input-accessor.hh"
#include "terminal.hh"
#include <sys/types.h>
#include <sys/socket.h>
@ -375,7 +376,9 @@ void mainWrapped(int argc, char * * argv)
setLogFormat("bar");
settings.verboseBuild = false;
if (isatty(STDERR_FILENO)) {
// If on a terminal, progress will be displayed via progress bars etc. (thus verbosity=notice)
if (nix::shouldANSI()) {
verbosity = lvlNotice;
} else {
verbosity = lvlInfo;

View file

@ -11,6 +11,7 @@
#include "legacy.hh"
#include "posix-source-accessor.hh"
#include "misc-store-flags.hh"
#include "terminal.hh"
#include <nlohmann/json.hpp>
@ -188,7 +189,7 @@ static int main_nix_prefetch_url(int argc, char * * argv)
Finally f([]() { stopProgressBar(); });
if (isatty(STDERR_FILENO))
if (shouldANSI())
startProgressBar();
auto store = openStore();