« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
m---------tui-lib0
-rw-r--r--ui.js41
2 files changed, 7 insertions, 34 deletions
diff --git a/tui-lib b/tui-lib
-Subproject 27c7e362d1f6719af0d2c47b815b23d648d699a
+Subproject d809ba2081041504998ad3b77c66b24e051f945
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
   }