diff options
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 && |