From 8c1eeb4681dc2acc60f23341d79470a0340ccdf5 Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Fri, 1 Mar 2024 23:13:00 +0100 Subject: [PATCH] treewide: shouldANSI() -> isTTY() --- src/libcmd/markdown.cc | 2 +- src/libmain/progress-bar.cc | 2 +- src/libutil/logging.cc | 2 +- src/libutil/terminal.cc | 2 +- src/libutil/terminal.hh | 2 +- src/nix-env/nix-env.cc | 2 +- src/nix/main.cc | 2 +- src/nix/prefetch.cc | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libcmd/markdown.cc b/src/libcmd/markdown.cc index a4e3c5a77..d62ff0d96 100644 --- a/src/libcmd/markdown.cc +++ b/src/libcmd/markdown.cc @@ -50,7 +50,7 @@ std::string renderMarkdownToTerminal(std::string_view markdown) if (!rndr_res) throw Error("allocation error while rendering Markdown"); - return filterANSIEscapes(std::string(buf->data, buf->size), !shouldANSI()); + return filterANSIEscapes(std::string(buf->data, buf->size), !isTTY()); #else return std::string(markdown); #endif diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index afba29e1b..ce45eae2b 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -537,7 +537,7 @@ public: Logger * makeProgressBar() { - return new ProgressBar(shouldANSI()); + return new ProgressBar(isTTY()); } void startProgressBar() diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 89fbd194a..83db492ca 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -52,7 +52,7 @@ public: : printBuildLogs(printBuildLogs) { systemd = getEnv("IN_SYSTEMD") == "1"; - tty = shouldANSI(); + tty = isTTY(); } bool isVerbose() override { diff --git a/src/libutil/terminal.cc b/src/libutil/terminal.cc index 8febc8771..2ff923405 100644 --- a/src/libutil/terminal.cc +++ b/src/libutil/terminal.cc @@ -7,7 +7,7 @@ namespace nix { -bool shouldANSI() +bool isTTY() { return isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb" diff --git a/src/libutil/terminal.hh b/src/libutil/terminal.hh index 9cb191308..9d8d0c743 100644 --- a/src/libutil/terminal.hh +++ b/src/libutil/terminal.hh @@ -8,7 +8,7 @@ namespace nix { * Determine whether ANSI escape sequences are appropriate for the * present output. */ -bool shouldANSI(); +bool isTTY(); /** * Truncate a string to 'width' printable characters. If 'filterAll' diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index b42fa06bc..0fa9501c1 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -1090,7 +1090,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) return; } - bool tty = shouldANSI(); + bool tty = isTTY(); RunPager pager; Table table; diff --git a/src/nix/main.cc b/src/nix/main.cc index c88b35005..22f9e7931 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -378,7 +378,7 @@ void mainWrapped(int argc, char * * argv) settings.verboseBuild = false; // If on a terminal, progress will be displayed via progress bars etc. (thus verbosity=notice) - if (nix::shouldANSI()) { + if (nix::isTTY()) { verbosity = lvlNotice; } else { verbosity = lvlInfo; diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index f96381408..b64e6d899 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -189,7 +189,7 @@ static int main_nix_prefetch_url(int argc, char * * argv) Finally f([]() { stopProgressBar(); }); - if (shouldANSI()) + if (isTTY()) startProgressBar(); auto store = openStore();