« get me outta code hell

Status line switcher - 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-14 17:16:04 -0300
committerFlorrie <towerofnix@gmail.com>2018-04-14 17:17:20 -0300
commit624807f73cbde2dabfed35f5cc3aa83b33638c15 (patch)
treefa6e3043a8c962567bd9249ead155b6aa2f6dfa0 /src
parent6e20b5d9b4dde541c270003494f4bb62700f3d04 (diff)
Status line switcher
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js25
-rwxr-xr-xsrc/play.js36
2 files changed, 53 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() {