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

View file

@ -16,6 +16,7 @@
#include "loggers.hh" #include "loggers.hh"
#include "markdown.hh" #include "markdown.hh"
#include "memory-input-accessor.hh" #include "memory-input-accessor.hh"
#include "terminal.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -375,7 +376,9 @@ void mainWrapped(int argc, char * * argv)
setLogFormat("bar"); setLogFormat("bar");
settings.verboseBuild = false; 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; verbosity = lvlNotice;
} else { } else {
verbosity = lvlInfo; verbosity = lvlInfo;

View file

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