mirror of
https://github.com/NixOS/nix
synced 2025-06-30 11:43:15 +02:00
Merge branch 'master' of https://github.com/NixOS/nix into parallel-xz
This commit is contained in:
commit
163e39547a
14 changed files with 221 additions and 103 deletions
|
@ -44,7 +44,7 @@ public:
|
|||
prefix = std::string("<") + c + ">";
|
||||
}
|
||||
|
||||
writeToStderr(prefix + (tty ? fs.s : filterANSIEscapes(fs.s)) + "\n");
|
||||
writeToStderr(prefix + filterANSIEscapes(fs.s) + "\n");
|
||||
}
|
||||
|
||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||
|
|
|
@ -1178,36 +1178,51 @@ void ignoreException()
|
|||
}
|
||||
|
||||
|
||||
string filterANSIEscapes(const string & s, bool nixOnly)
|
||||
std::string filterANSIEscapes(const std::string & s, unsigned int width)
|
||||
{
|
||||
string t, r;
|
||||
enum { stTop, stEscape, stCSI } state = stTop;
|
||||
for (auto c : s) {
|
||||
if (state == stTop) {
|
||||
if (c == '\e') {
|
||||
state = stEscape;
|
||||
r = c;
|
||||
} else
|
||||
t += c;
|
||||
} else if (state == stEscape) {
|
||||
r += c;
|
||||
if (c == '[')
|
||||
state = stCSI;
|
||||
else {
|
||||
t += r;
|
||||
state = stTop;
|
||||
std::string t, e;
|
||||
size_t w = 0;
|
||||
auto i = s.begin();
|
||||
|
||||
while (w < (size_t) width && i != s.end()) {
|
||||
|
||||
if (*i == '\e') {
|
||||
std::string e;
|
||||
e += *i++;
|
||||
char last = 0;
|
||||
|
||||
if (i != s.end() && *i == '[') {
|
||||
e += *i++;
|
||||
// eat parameter bytes
|
||||
while (i != s.end() && *i >= 0x30 && *i <= 0x3f) e += *i++;
|
||||
// eat intermediate bytes
|
||||
while (i != s.end() && *i >= 0x20 && *i <= 0x2f) e += *i++;
|
||||
// eat final byte
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x7e) e += last = *i++;
|
||||
} else {
|
||||
if (i != s.end() && *i >= 0x40 && *i <= 0x5f) e += *i++;
|
||||
}
|
||||
} else {
|
||||
r += c;
|
||||
if (c >= 0x40 && c <= 0x7e) {
|
||||
if (nixOnly && (c != 'p' && c != 'q' && c != 's' && c != 'a' && c != 'b'))
|
||||
t += r;
|
||||
state = stTop;
|
||||
r.clear();
|
||||
|
||||
if (last == 'm')
|
||||
t += e;
|
||||
}
|
||||
|
||||
else if (*i == '\t') {
|
||||
i++; t += ' '; w++;
|
||||
while (w < (size_t) width && w % 8) {
|
||||
t += ' '; w++;
|
||||
}
|
||||
}
|
||||
|
||||
else if (*i == '\r')
|
||||
// do nothing for now
|
||||
;
|
||||
|
||||
else {
|
||||
t += *i++; w++;
|
||||
}
|
||||
}
|
||||
t += r;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -388,10 +388,12 @@ void ignoreException();
|
|||
#define ANSI_BLUE "\e[34;1m"
|
||||
|
||||
|
||||
/* Filter out ANSI escape codes from the given string. If ‘nixOnly’ is
|
||||
set, only filter escape codes generated by Nixpkgs' stdenv (used to
|
||||
denote nesting etc.). */
|
||||
string filterANSIEscapes(const string & s, bool nixOnly = false);
|
||||
/* 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. */
|
||||
std::string filterANSIEscapes(const std::string & s,
|
||||
unsigned int width = std::numeric_limits<unsigned int>::max());
|
||||
|
||||
|
||||
/* Base64 encoding/decoding. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue