diff options
author | Florrie <towerofnix@gmail.com> | 2019-08-22 11:39:32 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-08-22 11:39:32 -0300 |
commit | d809ba2081041504998ad3b77c66b24e051f9458 (patch) | |
tree | c262357c7e4041b865ca3d2024cc7584ee995126 /util | |
parent | 27c7e362d1f6719af0d2c47b815b23d648d699a6 (diff) |
Add trimToColumns ansi utility function
Diffstat (limited to 'util')
-rw-r--r-- | util/ansi.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/util/ansi.js b/util/ansi.js index d58684f..6f3e23e 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -143,6 +143,21 @@ const ansi = { return wcwidth(text) }, + trimToColumns(text, cols) { + // Trims off the end of the passed text so that its width doesn't exceed + // the size passed in columns. + + let out = '' + for (const char of text) { + if (ansi.measureColumns(out + char) <= cols) { + out += char + } else { + break + } + } + return out + }, + isANSICommand(buffer, code = null) { return ( buffer[0] === 0x1b && buffer[1] === 0x5b && |