diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/wrap.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/util/wrap.js b/util/wrap.js index 3c381d4..71a1f1c 100644 --- a/util/wrap.js +++ b/util/wrap.js @@ -1,3 +1,5 @@ +const ansi = require('./ansi') + module.exports = function wrap(str, width) { // Wraps a string into separate lines. Returns an array of strings, for // each line of the text. @@ -6,13 +8,17 @@ module.exports = function wrap(str, width) { const words = str.split(' ') let curLine = words[0] + let curColumns = ansi.measureColumns(curLine) for (const word of words.slice(1)) { - if (curLine.length + word.length > width) { + const wordColumns = ansi.measureColumns(word) + if (curColumns + wordColumns > width) { lines.push(curLine) curLine = word + curColumns = wordColumns } else { curLine += ' ' + word + curColumns += 1 + wordColumns } } |