« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/util/ansi.js
diff options
context:
space:
mode:
Diffstat (limited to 'util/ansi.js')
-rw-r--r--util/ansi.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/ansi.js b/util/ansi.js
index ac511ed..f921349 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -153,7 +153,12 @@ const ansi = {
   },
 
   measureColumns(text) {
-    // Returns the number of columns the given text takes.
+    // Returns the number of columns the given text takes. Accounts for escape
+    // codes (by not including them in the returned width).
+
+    if (text.includes(ESC)) {
+      text = text.replace(new RegExp(ESC + '\\[\\??[0-9]*.', 'g'), '')
+    }
 
     return wcwidth(text)
   },