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 --- tui-lib | 2 +- ui.js | 41 +++++++---------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/tui-lib b/tui-lib index 27c7e36..d809ba2 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit 27c7e362d1f6719af0d2c47b815b23d648d699a6 +Subproject commit d809ba2081041504998ad3b77c66b24e051f9458 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