diff options
-rw-r--r-- | README.md | 4 | ||||
m--------- | tui-lib | 0 | ||||
-rw-r--r-- | ui.js | 63 |
3 files changed, 52 insertions, 15 deletions
diff --git a/README.md b/README.md index e0de494..2e9e26e 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,14 @@ * <kbd>Space</kbd>, <kbd>p</kbd>, or <kbd>k</kbd> - toggle pause * <kbd>Right</kbd> or <kbd>l</kbd> - seek ahead * <kbd>Left</kbd> or <kbd>j</kbd> - seek back -* <kbd>s</kbd> - shuffle the queue * **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>d</kbd> - download the selected track (but don't play it) +* **In the queue listing:** + * <kbd>s</kbd> - shuffle the queue + * <kbd>c</kbd> - clear the queue * **In path displays:** (Path displays are the things that show below the main and queue listings. They show the path of groups to the selected item in the listing.) * <kbd>Enter</kbd> or <kbd>Space</kbd> - view the selected item in the main listing * <kbd>Left</kbd> and <kbd>Right</kbd> - navigate the path display diff --git a/tui-lib b/tui-lib -Subproject c42add3c9edb6446a759ae4f5a2b3e81cf56f4f +Subproject 62348f48fbe2da7ab2af0e3ea71b0fbe7380b31 diff --git a/ui.js b/ui.js index 47c50a8..6e7aad1 100644 --- a/ui.js +++ b/ui.js @@ -50,8 +50,7 @@ class AppElement extends FocusElement { this.grouplikeListingElement.on('queue', item => this.queueGrouplikeItem(item)) const handleSelectFromPathElement = item => { - this.form.curIndex = this.form.inputs.indexOf(this.grouplikeListingElement) - this.root.select(this.grouplikeListingElement) + this.form.selectInput(this.grouplikeListingElement) if (isGroup(item)) { this.grouplikeListingElement.loadGrouplike(item) } else if (item[parentSymbol]) { @@ -64,7 +63,7 @@ class AppElement extends FocusElement { this.form.addInput(this.grouplikeListingElement.pathElement, false) this.grouplikeListingElement.pathElement.on('select', item => handleSelectFromPathElement(item)) - this.queueListingElement = new GrouplikeListingElement(this.recordStore) + this.queueListingElement = new QueueListingElement(this.recordStore) this.queueListingElement.loadGrouplike(this.queueGrouplike) this.paneRight.addChild(this.queueListingElement) this.form.addInput(this.queueListingElement, false) @@ -72,6 +71,8 @@ class AppElement extends FocusElement { this.queueListingElement.on('select (enter)', item => this.playGrouplikeItem(item, false)) this.queueListingElement.on('select (space)', item => this.handleSpacePressed( () => this.playGrouplikeItem(item, false))) + this.queueListingElement.on('shuffle', () => this.shuffleQueue()) + this.queueListingElement.on('clear', () => this.clearQueue()) this.paneRight.addChild(this.queueListingElement.pathElement) this.form.addInput(this.queueListingElement.pathElement, false) @@ -144,8 +145,6 @@ class AppElement extends FocusElement { } else if (telc.isCharacter(keyBuf, '2') && this.queueListingElement.selectable) { this.form.curIndex = this.form.inputs.indexOf(this.queueListingElement) this.form.updateSelectedElement() - } else if (telc.isCaselessLetter(keyBuf, 's')) { - this.shuffleQueue() } else { super.keyPressed(keyBuf) } @@ -161,6 +160,13 @@ class AppElement extends FocusElement { this.queueListingElement.buildItems() } + clearQueue() { + this.form.selectInput(this.grouplikeListingElement) + this.queueGrouplike.items = [] + this.queueListingElement.buildItems() + this.queueListingElement.pathElement.showItem(null) + } + handleSpacePressed(callback) { // Pauses/resumes if a track is currently playing; otherwise, calls the // callback function. @@ -293,66 +299,75 @@ class AppElement extends FocusElement { if (playingThisTrack) { this.playingTrack = null - this.playNextTrack(item) + if (!this.playNextTrack(item)) { + this.clearPlayingTrack() + } } } playNextTrack(track) { if (!track) { - return + return false } const queue = this.queueGrouplike let queueIndex = queue.items.indexOf(track) if (queueIndex === -1) { - queueIndex = queue.items.length + return false } queueIndex++ if (queueIndex >= queue.items.length) { const parent = track[parentSymbol] if (!parent) { - return + return false } const index = parent.items.indexOf(track) const nextItem = parent.items[index + 1] if (!nextItem) { - return + return false } this.queueGrouplikeItem(nextItem, false) queueIndex = queue.items.length - 1 } this.playGrouplikeItem(queue.items[queueIndex], false) + return true } playPreviousTrack(track) { if (!track) { - return + return false } const queue = this.queueGrouplike let queueIndex = queue.items.indexOf(track) if (queueIndex === -1) { - queueIndex = queue.items.length + return false } queueIndex-- if (queueIndex < 0) { const parent = track[parentSymbol] if (!parent) { - return + return false } const index = parent.items.indexOf(track) const previousItem = parent.items[index - 1] if (!previousItem) { - return + return false } this.queueGrouplikeItem(previousItem, false, 'FRONT') queueIndex = 0 } this.playGrouplikeItem(queue.items[queueIndex], false) + return true + } + + clearPlayingTrack() { + this.playingTrack = null + this.playbackInfoElement.clearInfo() } } @@ -608,6 +623,18 @@ class PathItemElement extends FocusElement { } } +class QueueListingElement extends GrouplikeListingElement { + keyPressed(keyBuf) { + if (telc.isCaselessLetter(keyBuf, 's')) { + this.emit('shuffle') + } else if (telc.isCaselessLetter(keyBuf, 'c')) { + this.emit('clear') + } else { + return super.keyPressed(keyBuf) + } + } +} + class PlaybackInfoElement extends DisplayElement { constructor() { super() @@ -648,6 +675,14 @@ class PlaybackInfoElement extends DisplayElement { this.downloadLabel.text = `(From: ${track.downloaderArg})` this.fixLayout() } + + clearInfo() { + this.progressBarLabel.text = '' + this.progressTextLabel.text = '' + this.trackNameLabel.text = '' + this.downloadLabel.text = '' + this.fixLayout() + } } module.exports.AppElement = AppElement |