« 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:
-rw-r--r--backend.js4
-rw-r--r--socket.js22
-rw-r--r--ui.js23
3 files changed, 37 insertions, 12 deletions
diff --git a/backend.js b/backend.js
index 0864d09..cf85ea1 100644
--- a/backend.js
+++ b/backend.js
@@ -885,7 +885,7 @@ export default class Backend extends EventEmitter {
     return download(item, this.getRecordFor(item))
   }
 
-  showLogMessage(text) {
-    this.emit('log message', text)
+  showLogMessage(text, isVerbose = false) {
+    this.emit('log message', text, isVerbose)
   }
 }
diff --git a/socket.js b/socket.js
index 5d4f85a..db1dfff 100644
--- a/socket.js
+++ b/socket.js
@@ -420,7 +420,8 @@ export function attachBackendToSocketClient(backend, client, {
     const nickToMessage = nickname => `\x1b[32;1m${nickname}\x1b[0m`
     const itemToMessage = item => `\x1b[32m"${item.name}"\x1b[0m`
     let fullmsg = '' // may be overridden
-    let actionmsg = `sent ${command.code}` // fallback
+    let actionmsg = `sent ${command.code} (no action message specified)`
+    let isVerbose = false
     switch (command.code) {
       case 'clear-queue':
         actionmsg = 'cleared the queue'
@@ -476,13 +477,28 @@ export function attachBackendToSocketClient(backend, client, {
         actionmsg = `removed ${itemToMessage(command.topItem)} from the queue`
         break
       case 'status':
-        return
+        isVerbose = true
+        switch (command.status) {
+          case 'ready-to-resume':
+            actionmsg = `is ready to play!`
+            break
+          case 'done-playing':
+            actionmsg = `has finished playing`
+            break
+          case 'sync-playback':
+            actionmsg = `synced playback with the server`
+            break
+          default:
+            actionmsg = `sent status "${command.status}"`
+            break
+        }
+        break
     }
     if (!fullmsg) {
       const nickname = command.sender === 'server' ? 'the server' : command.senderNickname
       fullmsg = `${nickToMessage(nickname)} ${actionmsg}`
     }
-    backend.showLogMessage(fullmsg)
+    backend.showLogMessage(fullmsg, isVerbose)
   }
 
   client.on('sent-command', command => {
diff --git a/ui.js b/ui.js
index 12898f2..7ed9b57 100644
--- a/ui.js
+++ b/ui.js
@@ -576,8 +576,8 @@ export default class AppElement extends FocusElement {
     this.updateQueueLengthLabel()
   }
 
-  handleLogMessage(text) {
-    this.log.newLogMessage(text)
+  handleLogMessage(text, isVerbose) {
+    this.log.newLogMessage(text, isVerbose)
   }
 
   async handlePlayingDetails(track, oldTrack, startTime, queuePlayer) {
@@ -5535,12 +5535,12 @@ class Log extends ListScrollForm {
     super('vertical')
   }
 
-  newLogMessage(text) {
+  newLogMessage(text, isVerbose = false) {
     if (this.inputs.length === 10) {
       this.removeInput(this.inputs[0])
     }
 
-    const logMessage = new LogMessage(text)
+    const logMessage = new LogMessage(text, isVerbose)
     this.addInput(logMessage)
     this.fixLayout()
     this.scrollToEnd()
@@ -5550,10 +5550,10 @@ class Log extends ListScrollForm {
 }
 
 class LogMessage extends FocusElement {
-  constructor(text) {
+  constructor(text, isVerbose = false) {
     super()
 
-    this.label = new LogMessageLabel(text)
+    this.label = new LogMessageLabel(text, isVerbose)
     this.addChild(this.label)
   }
 
@@ -5572,6 +5572,12 @@ class LogMessage extends FocusElement {
 }
 
 class LogMessageLabel extends WrapLabel {
+  constructor(text, isVerbose = false) {
+    super(text)
+
+    this.isVerbose = isVerbose
+  }
+
   writeTextTo(writable) {
     const w = this.w
     const lines = this.getWrappedLines()
@@ -5590,6 +5596,9 @@ class LogMessageLabel extends WrapLabel {
   set textAttributes(val) {}
 
   get textAttributes() {
-    return this.parent.isSelected ? [40] : []
+    return [
+      this.parent.isSelected ? 40 : null,
+      this.isVerbose ? 2 : null
+    ].filter(x => x !== null)
   }
 }