« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--ui.js25
2 files changed, 20 insertions, 8 deletions
diff --git a/README.md b/README.md
index db5a817..53a31c7 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,8 @@ playlist.json file (usually generated by http-music or downloaded from online).
 * **In the main listing:**
   * <kbd>Enter</kbd> - if the selected item is a group, enter it; otherwise play it
   * <kbd>Backspace</kbd> - leave the current group (if in one)
-  * <kbd>q</kbd> - queue the selected track to play after any other items in the queue (usually after the current track)
+  * <kbd>q</kbd> - queue the selected track or group to play after any other items in the queue (usually after the current track)
+  * <kbd>Q</kbd> (shift+Q) - queue the selected group, but shuffled
   * <kbd>d</kbd> - download the selected track (but don't play it)
 * **In the queue listing:**
   * <kbd>s</kbd> - shuffle the queue
diff --git a/ui.js b/ui.js
index 9a5b727..21ac9df 100644
--- a/ui.js
+++ b/ui.js
@@ -1,6 +1,6 @@
 const { getDownloaderFor } = require('./downloaders')
 const { getPlayer } = require('./players')
-const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString } = require('./playlist-utils')
+const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString, flattenGrouplike } = require('./playlist-utils')
 const { shuffleArray } = require('./general-util')
 const ansi = require('./tui-lib/util/ansi')
 const Button = require('./tui-lib/ui/form/Button')
@@ -55,6 +55,7 @@ class AppElement extends FocusElement {
     this.grouplikeListingElement.on('select (space)', item => this.handleSpacePressed(
       () => handleSelectFromMain(item)))
     this.grouplikeListingElement.on('queue', item => this.queueGrouplikeItem(item))
+    this.grouplikeListingElement.on('queue (shuffled)', item => this.shuffleQueueGrouplikeItem(item))
 
     const handleSelectFromPathElement = item => {
       this.form.selectInput(this.grouplikeListingElement)
@@ -279,6 +280,14 @@ class AppElement extends FocusElement {
     this.queueListingElement.buildItems()
   }
 
+  shuffleQueueGrouplikeItem(item) {
+    if (!isGroup(item)) {
+      return this.queueGrouplikeItem(item)
+    }
+
+    return this.queueGrouplikeItem({items: shuffleArray(flattenGrouplike(item).items)})
+  }
+
   async downloadGrouplikeItem(item) {
     if (isGroup(item)) {
       // TODO: Download all children (recursively), show a confirmation prompt
@@ -524,11 +533,9 @@ class GrouplikeListingElement extends FocusElement {
     if (this.grouplike.items.length) {
       for (const item of this.grouplike.items) {
         const itemElement = new GrouplikeItemElement(item, this.recordStore)
-        itemElement.on('download', () => this.emit('download', item))
-        itemElement.on('remove', () => this.emit('remove', item))
-        itemElement.on('select (space)', () => this.emit('select (space)', item))
-        itemElement.on('select (enter)', () => this.emit('select (enter)', item))
-        itemElement.on('queue', () => this.emit('queue', item))
+        for (const evtName of ['download', 'remove', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)']) {
+          itemElement.on(evtName, () => this.emit(evtName, item))
+        }
         form.addInput(itemElement)
       }
     } else if (!this.grouplike.isTheQueue) {
@@ -674,7 +681,11 @@ class GrouplikeItemElement extends Button {
     if (telc.isCaselessLetter(keyBuf, 'd')) {
       this.emit('download')
     } else if (telc.isCaselessLetter(keyBuf, 'q')) {
-      this.emit('queue')
+      if (keyBuf[0] === 'q'.charCodeAt(0)) {
+        this.emit('queue')
+      } else {
+        this.emit('queue (shuffled)')
+      }
     } else if (telc.isBackspace(keyBuf)) {
       this.emit('remove')
     } else if (telc.isSpace(keyBuf)) {