From 8b4d67ddbbb8ea3eb2ad42d7c75a168bf809f33a Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 4 Jun 2018 23:41:09 -0300 Subject: C to clear queue --- README.md | 4 +++- tui-lib | 2 +- ui.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e0de494..2e9e26e 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,14 @@ * Space, p, or k - toggle pause * Right or l - seek ahead * Left or j - seek back -* s - shuffle the queue * **In the main listing:** * Enter - if the selected item is a group, enter it; otherwise play it * Backspace - leave the current group (if in one) * q - queue the selected track to play after any other items in the queue (usually after the current track) * d - download the selected track (but don't play it) +* **In the queue listing:** + * s - shuffle the queue + * c - 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.) * Enter or Space - view the selected item in the main listing * Left and Right - navigate the path display diff --git a/tui-lib b/tui-lib index c42add3..62348f4 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit c42add3c9edb6446a759ae4f5a2b3e81cf56f4f5 +Subproject commit 62348f48fbe2da7ab2af0e3ea71b0fbe7380b31e 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 -- cgit 1.3.0-6-gf8a5