« get me outta code hell

Experimental telnet server - 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>2019-07-06 00:16:02 -0300
committerFlorrie <towerofnix@gmail.com>2019-07-06 11:23:55 -0300
commit8512c44b6403c126bf961c0fd0c2798d6bfdfcea (patch)
tree626ac64af2fb889fd7ec1a1032d14df5a87d4ad6 /ui.js
parentf96eeceefc94256babe016b0e18b95f0cf467880 (diff)
Experimental telnet server
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js38
1 files changed, 26 insertions, 12 deletions
diff --git a/ui.js b/ui.js
index c2c3e67..4f73fe0 100644
--- a/ui.js
+++ b/ui.js
@@ -134,11 +134,16 @@ telc.isSelect = input.isSelect
 telc.isBackspace = input.isBackspace
 
 class AppElement extends FocusElement {
-  constructor(backend) {
+  constructor(backend, config = {}) {
     super()
 
     this.backend = backend
 
+    this.config = Object.assign({
+      menubarColor: 4, // blue
+      stopPlayingUponQuit: true
+    }, config)
+
     this.backend.on('playing', (track, oldTrack) => {
       if (track) {
         this.playbackInfoElement.updateTrack(track)
@@ -160,6 +165,10 @@ class AppElement extends FocusElement {
       this.metadataStatusLabel.text = `Processing metadata - ${remaining} to go.`
     })
 
+    this.backend.on('queue updated', () => {
+      this.queueListingElement.buildItems()
+    })
+
     // TODO: Move edit mode stuff to the backend!
     this.undoManager = new UndoManager()
     this.markGrouplike = {name: 'Marked', items: []}
@@ -171,6 +180,8 @@ class AppElement extends FocusElement {
     this.menubar = new Menubar(this.menu)
     this.addChild(this.menubar)
 
+    this.menubar.color = this.config.menubarColor
+
     this.paneLeft = new Pane()
     this.addChild(this.paneLeft)
 
@@ -571,7 +582,10 @@ class AppElement extends FocusElement {
   }
 
   async shutdown() {
-    await this.backend.stopPlaying()
+    if (this.config.stopPlayingUponQuit) {
+      await this.backend.stopPlaying()
+    }
+
     this.emit('quitRequested')
   }
 
@@ -708,12 +722,10 @@ class AppElement extends FocusElement {
 
   shuffleQueue() {
     this.backend.shuffleQueue()
-    this.queueListingElement.buildItems()
   }
 
   clearQueue() {
     this.backend.clearQueue()
-    this.queueListingElement.buildItems()
     this.queueListingElement.selectNone()
     this.updateQueueLengthLabel()
 
@@ -756,7 +768,6 @@ class AppElement extends FocusElement {
       this.backend.queue(item, afterItem, {
         movePlayingTrack: order === 'normal'
       })
-      this.queueListingElement.buildItems()
 
       if (isTrack(passedItem)) {
         this.queueListingElement.selectAndShow(passedItem)
@@ -765,7 +776,6 @@ class AppElement extends FocusElement {
       this.backend.distributeQueue(item, {
         how: where.slice('distribute-'.length)
       })
-      this.queueListingElement.buildItems()
     }
 
     this.updateQueueLengthLabel()
@@ -1965,12 +1975,16 @@ class PlaybackInfoElement extends DisplayElement {
   }
 
   updateTrack(track) {
-    this.currentTrack = track
-    this.trackNameLabel.text = track.name
-    this.progressBarLabel.text = ''
-    this.progressTextLabel.text = '(Starting..)'
-    this.timeData = {}
-    this.fixLayout()
+    if (track) {
+      this.currentTrack = track
+      this.trackNameLabel.text = track.name
+      this.progressBarLabel.text = ''
+      this.progressTextLabel.text = '(Starting..)'
+      this.timeData = {}
+      this.fixLayout()
+    } else {
+      this.clearInfo()
+    }
   }
 
   clearInfo() {