From c9f3eac0197a1d7469b3a9cf64351a8fb0bcba5b Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 22 Aug 2019 11:40:17 -0300 Subject: Tidy computeText function for grouplike items --- ui.js | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index a02c85f..19200e7 100644 --- a/ui.js +++ b/ui.js @@ -1540,12 +1540,6 @@ class BasicGrouplikeItemElement extends Button { } computeText() { - let text = '' - let done = false - let heckingWatchOut = false - - // TODO: Hide right text if there's not enough columns (plus some padding) - // 3 = width of status line, basically let w = this.w - this.x - 3 @@ -1556,39 +1550,18 @@ class BasicGrouplikeItemElement extends Button { w -= rightTextCols } - const writable = { - write: characters => { - if (heckingWatchOut && done) { - return - } + let text = ansi.trimToColumns(this.text, w) - for (const char of characters) { - if (heckingWatchOut) { - if (ansi.measureColumns(text + char) <= w) { - text += char - } else { - done = true - break - } - } else { - text += char - } - } - } + const width = ansi.measureColumns(this.text) + if (width < w) { + text += ' '.repeat(w - width) } - // This is the part where we want to be careful to not go over the width - // limit.. - heckingWatchOut = true - writable.write(this.text) - heckingWatchOut = false - - const width = ansi.measureColumns(this.text) - writable.write(' '.repeat(Math.max(0, w - width))) if (showRightText) { - writable.write(this.rightText) + text += this.rightText } - writable.write(ansi.resetAttributes()) + + text += ansi.resetAttributes() this.drawText = text } -- cgit 1.3.0-6-gf8a5