« get me outta code hell

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:
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/ui.js b/ui.js
index 3952c38..c948080 100644
--- a/ui.js
+++ b/ui.js
@@ -547,8 +547,8 @@ class AppElement extends FocusElement {
     }
   }
 
-  handleLogMessage(text, isVerbose) {
-    this.log.newLogMessage(text, isVerbose)
+  handleLogMessage(messageInfo) {
+    this.log.newLogMessage(messageInfo)
   }
 
   async handlePlayingDetails(track, oldTrack, queuePlayer) {
@@ -4591,12 +4591,27 @@ class Log extends ListScrollForm {
     super('vertical')
   }
 
-  newLogMessage(text, isVerbose = false) {
+  newLogMessage(messageInfo) {
     if (this.inputs.length === 10) {
       this.removeInput(this.inputs[0])
     }
 
-    const logMessage = new LogMessage(text, isVerbose)
+    if (messageInfo.mayCombine) {
+      // If a message is specified to "combine", it'll replace an immediately
+      // previous message of the same code and sender.
+      const previous = this.inputs[this.inputs.length - 1]
+      if (
+        previous &&
+        previous.info.code === messageInfo.code &&
+        previous.info.sender === messageInfo.sender
+      ) {
+        // If the code and sender match, just remove the previous message.
+        // It'll be replaced by the one we're about to add!
+        this.removeInput(previous)
+      }
+    }
+
+    const logMessage = new LogMessage(messageInfo)
     this.addInput(logMessage)
     this.fixLayout()
     this.scrollToEnd()
@@ -4606,9 +4621,16 @@ class Log extends ListScrollForm {
 }
 
 class LogMessage extends FocusElement {
-  constructor(text, isVerbose = false) {
+  constructor(info) {
     super()
 
+    this.info = info
+
+    const {
+      text,
+      isVerbose = false
+    } = info
+
     this.label = new LogMessageLabel(text, isVerbose)
     this.addChild(this.label)
   }