« get me outta code hell

Make (t) key only show information about one track - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-03-07 19:15:26 -0400
committerFlorrie <towerofnix@gmail.com>2018-03-07 19:15:28 -0400
commit7c7d32d0136092d06f9747cc44c5a37bcc9832b8 (patch)
tree98bd40e2f2749dc15e69f7d8dcdadea444bd1b65 /src
parentc0f76f3de7cad551cd6170dc37f2f7ece6e025c5 (diff)
Make (t) key only show information about one track
The showTrackInfo keybinding command can now take a number of next/
previous tracks to show.
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js10
-rwxr-xr-xsrc/play.js7
2 files changed, 10 insertions, 7 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index b44e83f..0fd94e4 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -652,7 +652,11 @@ class PlayController extends EventEmitter {
     this.stopped = true
   }
 
-  logTrackInfo() {
+  logTrackInfo(upNextTrackCount = 3, previousTrackCount = undefined) {
+    if (typeof previousTrackCount === 'undefined') {
+      previousTrackCount = upNextTrackCount
+    }
+
     const getColorMessage = t => {
       if (!t) return '\x1b[2m(No track)\x1b[0m'
 
@@ -675,13 +679,13 @@ class PlayController extends EventEmitter {
     const tl = hc.timeline
     const tlI = hc.timelineIndex
 
-    for (let i = Math.max(0, tlI - 2); i < tlI; i++) {
+    for (let i = Math.max(0, tlI - (previousTrackCount - 1)); 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++) {
+    for (let i = tlI + 1; i < Math.min(tlI + upNextTrackCount, tl.length); i++) {
       console.log(`(Next) ${getCleanMessage(tl[i])}`)
     }
   }
diff --git a/src/play.js b/src/play.js
index 28fd2c7..0b521b4 100755
--- a/src/play.js
+++ b/src/play.js
@@ -114,7 +114,7 @@ async function main(args) {
     [['delete'], 'skipUpNext'],
     [['s'], 'skipAhead'], [['S'], 'skipAhead'],
     [['i'], 'showTrackInfo'], [['I'], 'showTrackInfo'],
-    [['t'], 'showTrackInfo'], [['T'], 'showTrackInfo'],
+    [['t'], 'showTrackInfo', 0, 0], [['T'], 'showTrackInfo', 0, 0],
     [['q'], 'quit'], [['Q'], 'quit']
   ]
 
@@ -788,10 +788,9 @@ async function main(args) {
         })
       },
 
-      // TODO: Number of history/up-next tracks to show.
-      'showTrackInfo': function() {
+      'showTrackInfo': function(previousTrackCount = 3, upNextTrackCount = undefined) {
         clearConsoleLine()
-        playController.logTrackInfo()
+        playController.logTrackInfo(previousTrackCount, upNextTrackCount)
       },
 
       'runShellCommand': async function(command, args) {