Respect TERM=dumb more consistently

This commit is contained in:
Yestin L. Harrison 2021-07-01 18:19:01 -06:00
parent 139f7af5ec
commit 20cce079f2
4 changed files with 9 additions and 2 deletions

View file

@ -484,7 +484,7 @@ Logger * makeProgressBar(bool printBuildLogs)
{ {
return new ProgressBar( return new ProgressBar(
printBuildLogs, printBuildLogs,
isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb" shouldANSI()
); );
} }

View file

@ -46,7 +46,7 @@ public:
: printBuildLogs(printBuildLogs) : printBuildLogs(printBuildLogs)
{ {
systemd = getEnv("IN_SYSTEMD") == "1"; systemd = getEnv("IN_SYSTEMD") == "1";
tty = isatty(STDERR_FILENO); tty = shouldANSI();
} }
bool isVerbose() override { bool isVerbose() override {

View file

@ -1372,6 +1372,10 @@ void ignoreException()
} }
} }
bool shouldANSI()
{
return isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb";
}
std::string filterANSIEscapes(const std::string & s, bool filterAll, unsigned int width) std::string filterANSIEscapes(const std::string & s, bool filterAll, unsigned int width)
{ {

View file

@ -482,6 +482,9 @@ constexpr char treeLast[] = "└───";
constexpr char treeLine[] = ""; constexpr char treeLine[] = "";
constexpr char treeNull[] = " "; constexpr char treeNull[] = " ";
/* Determine whether ANSI escape sequences are appropriate for the
present output. */
bool shouldANSI();
/* Truncate a string to 'width' printable characters. If 'filterAll' /* Truncate a string to 'width' printable characters. If 'filterAll'
is true, all ANSI escape sequences are filtered out. Otherwise, is true, all ANSI escape sequences are filtered out. Otherwise,