diff options
-rw-r--r-- | src/loop-play.js | 25 | ||||
-rwxr-xr-x | src/play.js | 36 | ||||
-rw-r--r-- | todo.txt | 2 |
3 files changed, 55 insertions, 8 deletions
diff --git a/src/loop-play.js b/src/loop-play.js index e1e870d..9d073e5 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -370,7 +370,7 @@ class DownloadController extends EventEmitter { class PlayController extends EventEmitter { constructor({ player, playlist, historyController, downloadController, - statusLineTemplate = '%longIndex% (%percentDone%) %timeDone% / %duration%', + statusLineTemplates = ['%timeLeft%'], titleLineTemplate = '', useConverterOptions = true, trackDisplayFile = null // File to output current track path to. @@ -389,6 +389,8 @@ class PlayController extends EventEmitter { this.nextFile = undefined // TODO: Why isn't this null? this.stopped = false this.shouldMoveNext = true + this.statusLineTemplates = statusLineTemplates + this.statusLineIndex = statusLineTemplates.length - 1 this.failedCount = 0 this.playFailCount = 0 @@ -474,7 +476,8 @@ class PlayController extends EventEmitter { trackTitle: track.title, title: track.title }, playerData) - fullStatusLine += processTemplateString(statusLineTemplate, replacements) + fullStatusLine += processTemplateString( + statusLineTemplates[this.statusLineIndex], replacements) // Clear format - custom color codes, etc. fullStatusLine += '\x1b[0m' @@ -725,6 +728,20 @@ class PlayController extends EventEmitter { console.log(`(Next) ${getCleanMessage(tl[i])}`) } } + + nextStatusLine() { + this.statusLineIndex++ + if (this.statusLineIndex >= this.statusLineTemplates.length) { + this.statusLineIndex = 0 + } + } + + previousStatusLine() { + this.statusLineIndex-- + if (this.statusLineIndex < 0) { + this.statusLineIndex = this.statusLineTemplates.length - 1 + } + } } module.exports = async function startLoopPlay( @@ -734,7 +751,7 @@ module.exports = async function startLoopPlay( disablePlaybackStatus = false, startTrack = null, trackDisplayFile = null, - statusLineTemplate = undefined, + statusLineTemplates = undefined, titleLineTemplate = undefined } ) { @@ -780,7 +797,7 @@ module.exports = async function startLoopPlay( const playController = new PlayController({ player, playlist, historyController, downloadController, - trackDisplayFile, statusLineTemplate, titleLineTemplate + trackDisplayFile, statusLineTemplates, titleLineTemplate }) Object.assign(playController, {useConverterOptions}) diff --git a/src/play.js b/src/play.js index 7e70db3..619cf55 100755 --- a/src/play.js +++ b/src/play.js @@ -81,7 +81,10 @@ async function main(args) { let trackDisplayFile // The (custom) status line template strings. - let statusLineTemplate + let statusLineTemplates = [ + '%longIndex% (%percentDone%) %timeDone% / %timeLeft%', + '%longIndex% (%percentDone%) %timeDone% / %duration%' + ] let titleLineTemplate const keybindings = [ @@ -97,6 +100,8 @@ async function main(args) { [['i'], 'showTrackInfo'], [['I'], 'showTrackInfo'], [['t'], 'showTrackInfo', 0, 0], [['T'], 'showTrackInfo', 0, 0], [['%'], 'showTrackInfo', 20, 0], + [['<'], 'previousStatusLine'], + [['>'], 'nextStatusLine'], [['q'], 'quit'], [['Q'], 'quit'] ] @@ -391,8 +396,8 @@ async function main(args) { // which means you can use text such as %timeLeft% and %duration% and // these will be replaced with appropriate values.) - statusLineTemplate = util.nextArg() - console.log('Using custom status line:', statusLineTemplate) + statusLineTemplates = [util.nextArg()] + console.log('Using custom status line:', statusLineTemplates[0]) }, '-playback-status': util => util.alias('-status-line'), @@ -400,6 +405,21 @@ async function main(args) { '-playback-line': util => util.alias('-status-line'), '-status': util => util.alias('-status-line'), + '-add-status-line': function(util) { + // --add-status-line <string> (alias: all the same ones as --status-line) + // Works basically the same as --status-line, but adds a status line that + // can be switched to using the "<" and ">" keys. The most-recently-added + // status line is the one that's selected by default. + + const line = util.nextArg() + if (statusLineTemplates) { + statusLineTemplates.push(line) + } else { + statusLineTemplates = [line] + } + console.log('Adding a quick-switch status line:', line) + }, + '-title-status-line': function(util) { // --title-status-line <string> (alias: --title) // Sets the text to be displayed in the title of the terminal window. @@ -517,7 +537,7 @@ async function main(args) { willUseConverterOptions === null && shouldUseConverterOptions ), disablePlaybackStatus, - statusLineTemplate, + statusLineTemplates, titleLineTemplate, startTrack, trackDisplayFile @@ -572,6 +592,14 @@ async function main(args) { } }, + 'nextStatusLine': function() { + playController.nextStatusLine() + }, + + 'previousStatusLine': function() { + playController.previousStatusLine() + }, + // TODO: Skip back/ahead multiple tracks at once 'skipBack': function() { diff --git a/todo.txt b/todo.txt index 1eb211d..95f8c48 100644 --- a/todo.txt +++ b/todo.txt @@ -424,6 +424,7 @@ TODO: Make process-metadata work nicely with smart playlists, somehow... TODO: A way (key, option) to change the "/ duration" text in the status bar to "- remaining". This would work very nicely with the >/< status bar idea. + (Done!) TODO: Be a bit more loose (strict?) about what means crashing... Right now if five tracks fail to play in a row, http-music stops. This is good for @@ -453,3 +454,4 @@ TODO: A way to customize the tmux window title, somehow. I have no idea how working; we can just reuse the formatting code so that the user can customize what shows up (if anything) in the window title. Some will prefer the title of a song while others will prefer its duration! + (Done!) |