From 8734a491a21191f9fbc154c36154cbcaf977b2a8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 10 Apr 2018 10:54:15 -0300 Subject: Add --title-line option, for fancy tmux windows Also, "title" and "name" and "trackTitle" and "trackName" are all aliases for the same thing now. --- src/loop-play.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/loop-play.js') diff --git a/src/loop-play.js b/src/loop-play.js index 2fa7da7..e1e870d 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -371,6 +371,7 @@ class PlayController extends EventEmitter { constructor({ player, playlist, historyController, downloadController, statusLineTemplate = '%longIndex% (%percentDone%) %timeDone% / %duration%', + titleLineTemplate = '', useConverterOptions = true, trackDisplayFile = null // File to output current track path to. }) { @@ -462,19 +463,32 @@ class PlayController extends EventEmitter { const groupIndexArr = (track && track.groupTrackIndex) || ['', ''] - fullStatusLine += processTemplateString(statusLineTemplate, Object.assign({ + const replacements = Object.assign({ esc: '\x1b', index: track ? (track.overallTrackIndex[0] + 1) : '', trackCount: track ? (track.overallTrackIndex[1]) : '', indexGroup: groupIndexArr[0], trackCountGroup: groupIndexArr[1], longIndex, - trackName: track.name, name: track.name - }, playerData)) + trackName: track.name, name: track.name, + trackTitle: track.title, title: track.title + }, playerData) + + fullStatusLine += processTemplateString(statusLineTemplate, replacements) // Clear format - custom color codes, etc. fullStatusLine += '\x1b[0m' + if (titleLineTemplate) { + const title = processTemplateString(titleLineTemplate, replacements) + if (title) { + fullStatusLine += '\x1bk' + title + '\x1b\\' + } + } + + // Clear formatting again, juuuuust in case. + fullStatusLine += '\x1b[0m' + // Carriage return - moves the cursor back to the start of the line, // so that the next status line is printed on top of this one. fullStatusLine += '\r' @@ -720,7 +734,8 @@ module.exports = async function startLoopPlay( disablePlaybackStatus = false, startTrack = null, trackDisplayFile = null, - statusLineTemplate = undefined + statusLineTemplate = undefined, + titleLineTemplate = undefined } ) { // Looping play function. Takes a playlist and an object containing general @@ -765,7 +780,7 @@ module.exports = async function startLoopPlay( const playController = new PlayController({ player, playlist, historyController, downloadController, - trackDisplayFile, statusLineTemplate + trackDisplayFile, statusLineTemplate, titleLineTemplate }) Object.assign(playController, {useConverterOptions}) -- cgit 1.3.0-6-gf8a5