« get me outta code hell

Add utility measureColumns function to ansi.js - 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
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-12-05 16:40:46 -0400
committerFlorrie <towerofnix@gmail.com>2018-12-05 16:40:46 -0400
commitd59d12196ad00a51d76e0ef4b6808ec2978f7649 (patch)
treef2169f71edce85ce69d752024f2f60e6931dfe44 /util
parentbc5199c288bb93451927af0cc31a98cf0a25f843 (diff)
Add utility measureColumns function to ansi.js
This way layouts can properly support wide characters.
Diffstat (limited to 'util')
-rw-r--r--util/ansi.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/util/ansi.js b/util/ansi.js
index f0d7bf7..f976c12 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -113,6 +113,12 @@ const ansi = {
     return `${ESC}[6n`
   },
 
+  measureColumns(text) {
+    // Returns the number of columns the given text takes.
+
+    return wcwidth(text)
+  },
+
   isANSICommand(buffer, code = null) {
     return (
       buffer[0] === 0x1b && buffer[1] === 0x5b &&