« get me outta code hell

socket log messages & misc npm updates - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-07-17 18:48:32 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 19:09:51 -0300
commitf2f7f781edac78303e1b536f5da9977f9f30c56a (patch)
treeee57b33f9639e0b006c527510c565c06925d29b5 /ui.js
parentafeda69313e0250d654986ba0203974c56b30670 (diff)
socket log messages & misc npm updates
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/ui.js b/ui.js
index 05e359e..df02edf 100644
--- a/ui.js
+++ b/ui.js
@@ -5530,6 +5530,10 @@ class Log extends ListScrollForm {
   }
 
   newLogMessage(text) {
+    if (this.inputs.length === 10) {
+      this.removeInput(this.inputs[0])
+    }
+
     const logMessage = new LogMessage(text)
     this.addInput(logMessage)
     this.fixLayout()
@@ -5538,4 +5542,47 @@ class Log extends ListScrollForm {
   }
 }
 
-class LogMessage extends Button {}
+class LogMessage extends FocusElement {
+  constructor(text) {
+    super()
+
+    this.label = new LogMessageLabel(text)
+    this.addChild(this.label)
+  }
+
+  fixLayout() {
+    this.w = this.parent.contentW
+    this.label.w = this.contentW
+    this.h = this.label.h
+  }
+
+  clicked(button) {
+    if (button === 'left') {
+      this.root.select(this)
+      return false
+    }
+  }
+}
+
+class LogMessageLabel extends WrapLabel {
+  writeTextTo(writable) {
+    const w = this.w
+    const lines = this.getWrappedLines()
+    for (let i = 0; i < lines.length; i++) {
+      const text = this.processFormatting(lines[i])
+      writable.write(ansi.moveCursor(this.absTop + i, this.absLeft))
+      writable.write(text)
+      const width = ansi.measureColumns(text)
+      if (width < w && this.textAttributes.length) {
+        writable.write(ansi.setAttributes([ansi.A_RESET, ...this.textAttributes]))
+        writable.write(' '.repeat(w - width))
+      }
+    }
+  }
+
+  set textAttributes(val) {}
+
+  get textAttributes() {
+    return this.parent.isSelected ? [40] : []
+  }
+}