mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Filter ANSI colors when not writing to a terminal
Fixes https://github.com/NixOS/nixpkgs/issues/37114.
This commit is contained in:
parent
7b8914825a
commit
4868721506
4 changed files with 10 additions and 8 deletions
|
@ -53,7 +53,7 @@ public:
|
|||
prefix = std::string("<") + c + ">";
|
||||
}
|
||||
|
||||
writeToStderr(prefix + filterANSIEscapes(fs.s) + "\n");
|
||||
writeToStderr(prefix + filterANSIEscapes(fs.s, !tty) + "\n");
|
||||
}
|
||||
|
||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||
|
|
|
@ -1185,7 +1185,7 @@ void ignoreException()
|
|||
}
|
||||
|
||||
|
||||
std::string filterANSIEscapes(const std::string & s, unsigned int width)
|
||||
std::string filterANSIEscapes(const std::string & s, bool filterAll, unsigned int width)
|
||||
{
|
||||
std::string t, e;
|
||||
size_t w = 0;
|
||||
|
@ -1210,7 +1210,7 @@ std::string filterANSIEscapes(const std::string & s, unsigned int width)
|
|||
if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++;
|
||||
}
|
||||
|
||||
if (last == 'm')
|
||||
if (!filterAll && last == 'm')
|
||||
t += e;
|
||||
}
|
||||
|
||||
|
|
|
@ -391,11 +391,13 @@ void ignoreException();
|
|||
#define ANSI_BLUE "\e[34;1m"
|
||||
|
||||
|
||||
/* Truncate a string to 'width' printable characters. Certain ANSI
|
||||
escape sequences (such as colour setting) are copied but not
|
||||
included in the character count. Other ANSI escape sequences are
|
||||
filtered. Also, tabs are expanded to spaces. */
|
||||
/* Truncate a string to 'width' printable characters. If 'filterAll'
|
||||
is true, all ANSI escape sequences are filtered out. Otherwise,
|
||||
some escape sequences (such as colour setting) are copied but not
|
||||
included in the character count. Also, tabs are expanded to
|
||||
spaces. */
|
||||
std::string filterANSIEscapes(const std::string & s,
|
||||
bool filterAll = false,
|
||||
unsigned int width = std::numeric_limits<unsigned int>::max());
|
||||
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ public:
|
|||
auto width = getWindowSize().second;
|
||||
if (width <= 0) std::numeric_limits<decltype(width)>::max();
|
||||
|
||||
writeToStderr("\r" + filterANSIEscapes(line, width) + "\e[K");
|
||||
writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K");
|
||||
}
|
||||
|
||||
std::string getStatus(State & state)
|
||||
|
|
Loading…
Reference in a new issue