diff options
-rw-r--r-- | package-lock.json | 5 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | ui/WrapLabel.js | 6 | ||||
-rw-r--r-- | util/wrap.js | 8 |
4 files changed, 10 insertions, 12 deletions
diff --git a/package-lock.json b/package-lock.json index 8530981..3a51d91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,11 +24,6 @@ "requires": { "defaults": "^1.0.3" } - }, - "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==" } } } diff --git a/package.json b/package.json index 2f3f82f..4308565 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "author": "Florrie <towerofnix@gmail.com>", "license": "GPL-3.0", "dependencies": { - "wcwidth": "^1.0.1", - "word-wrap": "^1.2.3" + "wcwidth": "^1.0.1" } } diff --git a/ui/WrapLabel.js b/ui/WrapLabel.js index babf462..7036908 100644 --- a/ui/WrapLabel.js +++ b/ui/WrapLabel.js @@ -1,5 +1,5 @@ const ansi = require('../util/ansi') -const wrap = require('word-wrap') +const wrap = require('../util/wrap') const Label = require('./Label') @@ -29,9 +29,7 @@ module.exports = class WrapLabel extends Label { return [] } - const options = {width: this.w, indent: ''} - return wrap(this.text, options).split('\n') - .map(l => l.trim()) + return wrap(this.text, this.w).map(l => l.trim()) } get h() { 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 } } |