diff options
author | Florrie <towerofnix@gmail.com> | 2020-07-16 14:04:25 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2020-07-16 14:05:39 -0300 |
commit | 7f0579fc6e5771bbcad36591ab54119c4fe66dbd (patch) | |
tree | 408c1ee3789645e5e89533a4bf7d9746719175a5 /util | |
parent | cff17d1f056a73714ff1ba5a735987d140a6b51c (diff) |
improve & use our own word wrapping code
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 } } |