From 7c7d32d0136092d06f9747cc44c5a37bcc9832b8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 7 Mar 2018 19:15:26 -0400 Subject: Make (t) key only show information about one track The showTrackInfo keybinding command can now take a number of next/ previous tracks to show. --- man/http-music-play.1 | 9 +++++++-- src/loop-play.js | 10 +++++++--- src/play.js | 7 +++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/man/http-music-play.1 b/man/http-music-play.1 index 978e00c..97e8475 100644 --- a/man/http-music-play.1 +++ b/man/http-music-play.1 @@ -54,8 +54,8 @@ Pauses (or resumes) playback. .TP .BR i -Shows information (title, URL/path) on the currently playing track. -(\fBt\fR also works.) +Shows information (title, URL/path) about the currently playing track, as well as the upcoming and previously-played three tracks. +(Use \fBt\fR to see information about just the current track.) .TP .BR p @@ -72,6 +72,11 @@ Quits the http-music process and stops music currently being played. Skips past the track that's currently playing. (\fB\fR also works.) +.TP +.BR t +Shows information about the track that's currently playing. +(Use \fBi\fR to also see previous and upcoming tracks.) + .SH OPTIONS .TP 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) { -- cgit 1.3.0-6-gf8a5