From 7f0579fc6e5771bbcad36591ab54119c4fe66dbd Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 16 Jul 2020 14:04:25 -0300 Subject: improve & use our own word wrapping code --- util/wrap.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'util') 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 } } -- cgit 1.3.0-6-gf8a5