« get me outta code hell

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:
Diffstat (limited to 'src/loop-play.js')
-rw-r--r--src/loop-play.js25
1 files changed, 20 insertions, 5 deletions
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})