« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js44
-rw-r--r--src/playlist-utils.js2
2 files changed, 32 insertions, 14 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index 01e1574..09b3cad 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -96,7 +96,9 @@ class MPVPlayer extends Player {
         const curSecTotal = (3600 * curHour) + (60 * curMin) + (1 * curSec)
         const lenSecTotal = (3600 * lenHour) + (60 * lenMin) + (1 * lenSec)
         const percentVal = (100 / lenSecTotal) * curSecTotal
-        const percentStr = (Math.trunc(percentVal * 100) / 100).toFixed(2)
+        const percentStr = (
+          (Math.trunc(percentVal * 100) / 100).toFixed(2) + '%'
+        )
 
         this.printStatusLine(createStatusLine({percentStr, curStr, lenStr}))
       }
@@ -363,27 +365,43 @@ class PlayController extends EventEmitter {
     this.player.on('printStatusLine', playerString => {
       let fullStatusLine = ''
 
+      // ESC[K - clears the line going from the cursor position onwards.
+      // This is here to avoid artefacts from a previously printed status line.
+      fullStatusLine += '\x1b[K'
+
       const track = this.currentTrack
 
       if (track) {
         if (track.overallTrackIndex || track.groupTrackIndex) {
           fullStatusLine += '('
 
-          if (track.overallTrackIndex) {
-            const [ cur, len ] = track.overallTrackIndex
-            fullStatusLine += `${cur + 1} / ${len}`
-
-            if (track.groupTrackIndex) {
-              fullStatusLine += ' [All]; '
+          addTrackNumberInnards: {
+            if (track.overallTrackIndex) {
+              const [ cur, len ] = track.overallTrackIndex
+              fullStatusLine += `${cur + 1} / ${len}`
+
+              if (track.groupTrackIndex) {
+                const [ curGroup, lenGroup ] = track.groupTrackIndex
+
+                // If the overall and group track indexes are equal to each
+                // other, there's a fair chance we're just playing a single
+                // group; so, we only display one index (and we don't show
+                // "[All]"/"[Group]" labels).
+                if (curGroup === cur && lenGroup === len) {
+                  break addTrackNumberInnards
+                } else {
+                  fullStatusLine += ' [All]; '
+                }
+              }
             }
-          }
 
-          if (track.groupTrackIndex) {
-            const [ cur, len ] = track.groupTrackIndex
-            fullStatusLine += `${cur + 1} / ${len}`
+            if (track.groupTrackIndex) {
+              const [ cur, len ] = track.groupTrackIndex
+              fullStatusLine += `${cur + 1} / ${len}`
 
-            if (track.overallTrackIndex) {
-              fullStatusLine += ' [Group]'
+              if (track.overallTrackIndex) {
+                fullStatusLine += ' [Group]'
+              }
             }
           }
 
diff --git a/src/playlist-utils.js b/src/playlist-utils.js
index c2f6aae..3983c7a 100644
--- a/src/playlist-utils.js
+++ b/src/playlist-utils.js
@@ -533,7 +533,7 @@ module.exports = {
   filterPlaylistByPathString, filterGrouplikeByPath,
   removeGroupByPathString, removeGroupByPath,
   getPlaylistTreeString,
-  getItemPathString,
+  getItemPath, getItemPathString,
   parsePathString,
   isSameTrack,
   getTrackIndexInParent,