« get me outta code hell

Add --title-line option, for fancy tmux windows - 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-04-10 10:54:15 -0300
committerFlorrie <towerofnix@gmail.com>2018-04-10 10:54:16 -0300
commit8734a491a21191f9fbc154c36154cbcaf977b2a8 (patch)
tree6880d5b67296f1bd46a2d5115a903de72f02ed8c /src
parent9fa51e49dd113072d32b5467422a443bf744407a (diff)
Add --title-line option, for fancy tmux windows
Also, "title" and "name" and "trackTitle" and "trackName" are all
aliases for the same thing now.
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js25
-rwxr-xr-xsrc/play.js21
2 files changed, 40 insertions, 6 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})
diff --git a/src/play.js b/src/play.js
index e9b5231..7e70db3 100755
--- a/src/play.js
+++ b/src/play.js
@@ -80,8 +80,9 @@ async function main(args) {
   // The file to write the playlist path of the current file to.
   let trackDisplayFile
 
-  // The (custom) status line template string.
+  // The (custom) status line template strings.
   let statusLineTemplate
+  let titleLineTemplate
 
   const keybindings = [
     [['space'], 'togglePause'],
@@ -396,8 +397,25 @@ async function main(args) {
 
     '-playback-status': util => util.alias('-status-line'),
     '-playback-status-line': util => util.alias('-status-line'),
+    '-playback-line': util => util.alias('-status-line'),
     '-status': util => util.alias('-status-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.
+      // This has particularly noticable use alongside utilities such as tmux
+      // and screen; for example, in tmux, the window list at the bottom of
+      // the screen will show the string here.  As with --status-line, this is
+      // a "template" string, of course. Setting this to an empty string
+      // disables the title status line (which is the default).
+
+      titleLineTemplate = util.nextArg()
+      console.log('Using custom title line:', titleLineTemplate)
+    },
+
+    '-title-line': util => util.alias('-title-status-line'),
+    '-title': util => util.alias('-title-status-line'),
+
     '-track-display-file': async function(util) {
       // --track-display-file  (alias: --display-track-file)
       // Sets the file to output the current track's path to every time a new
@@ -500,6 +518,7 @@ async function main(args) {
       ),
       disablePlaybackStatus,
       statusLineTemplate,
+      titleLineTemplate,
       startTrack,
       trackDisplayFile
     })