« get me outta code hell

Re-implement logTrackInfo; now shows previous/next tracks - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/loop-play.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-09-02 12:06:08 -0300
committerFlorrie <towerofnix@gmail.com>2017-09-02 12:06:08 -0300
commit281de70bbc9328e2b95b6296235b9b0845e54495 (patch)
tree03f19ba1b5bd1a1b5f921d1bff74ecdb316c9008 /src/loop-play.js
parent2efec475218b90411d92688b5d69247571340a96 (diff)
Re-implement logTrackInfo; now shows previous/next tracks
Diffstat (limited to 'src/loop-play.js')
-rw-r--r--src/loop-play.js34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index 24134b0..4274b3c 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -434,24 +434,36 @@ class PlayController extends EventEmitter {
   }
 
   logTrackInfo() {
-    const getMessage = t => {
-      let path = getItemPathString(t)
+    const getColorMessage = t => {
+      if (!t) return '\x1b[2m(No track)\x1b[0m'
+
+      const path = getItemPathString(t)
 
       return (
-        `\x1b[1m${t.name} \x1b[0m@ ${path} \x1b[2m${t.downloaderArg}\x1b[0m`
+        `\x1b[1m${t.name} \x1b[0m@ ${path} \x1b[2m(${t.downloaderArg})\x1b[0m`
       )
     }
 
-    if (this.currentTrack) {
-      console.log(`Playing: ${getMessage(this.currentTrack)}`)
-    } else {
-      console.log("No song currently playing.")
+    const getCleanMessage = t => {
+      if (!t) return '(No track)'
+
+      const path = getItemPathString(t)
+
+      return `${t.name} @ ${path}`
     }
 
-    if (this.nextTrack) {
-      console.log(`Up next: ${getMessage(this.nextTrack)}`)
-    } else {
-      console.log("No song up next.")
+    const hc = this.historyController
+    const tl = hc.timeline
+    const tlI = hc.timelineIndex - 1
+
+    for (let i = Math.max(0, tlI - 2); i < tlI; i++) {
+      console.log(`\x1b[2m(Prev) ${getCleanMessage(tl[i])}\x1b[0m`)
+    }
+
+    console.log(`\x1b[1m(Curr) \x1b[1m${getColorMessage(tl[tlI])}\x1b[0m`)
+
+    for (let i = tlI + 1; i < Math.min(tlI + 3, tl.length); i++) {
+      console.log(`(Next) ${getCleanMessage(tl[i])}`)
     }
   }
 }