about summary refs log tree commit diff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-02-07T14·19+0100
committerEelco Dolstra <edolstra@gmail.com>2018-02-07T14·23+0100
commit84989d3af23c717744b8ddeacd6828bc87e7eda1 (patch)
treeedbd50b08c19559a56c2b0350ed6f44c44c0e731 /src/libutil/util.hh
parentcfdfad5c3451731879a5a693059c094f107c2bc8 (diff)
Improve filtering of ANSI escape sequences in build logs
All ANSI sequences except color setting are now filtered out. In
particular, terminal resets (such as from NixOS VM tests) are filtered
out.

Also, fix the completely broken tab character handling.
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 75eb9751524e..47e02bc898a6 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -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. */