« 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.md1
-rw-r--r--ui.js10
2 files changed, 11 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2e9e26e..d971733 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@
 * <kbd><kbd>Shift</kbd>+<kbd>Up</kbd></kbd> - play previous track
 * <kbd><kbd>Shift</kbd>+<kbd>Down</kbd></kbd> - play next track
 * <kbd>Space</kbd>, <kbd>p</kbd>, or <kbd>k</kbd> - toggle pause
+* <kbd>Escape</kbd> - stop playing the current track
 * <kbd>Right</kbd> or <kbd>l</kbd> - seek ahead
 * <kbd>Left</kbd> or <kbd>j</kbd> - seek back
 * **In the main listing:**
diff --git a/ui.js b/ui.js
index 6e7aad1..7a524ee 100644
--- a/ui.js
+++ b/ui.js
@@ -135,6 +135,8 @@ class AppElement extends FocusElement {
       this.seekBack(10)
     } else if (telc.isCaselessLetter(keyBuf, 'p') || telc.isCaselessLetter(keyBuf, 'k')) {
       this.togglePause()
+    } else if (telc.isEscape(keyBuf)) {
+      this.clearPlayingTrack()
     } else if (telc.isShiftUp(keyBuf)) {
       this.playPreviousTrack(this.playingTrack)
     } else if (telc.isShiftDown(keyBuf)) {
@@ -190,6 +192,13 @@ class AppElement extends FocusElement {
     this.player.togglePause()
   }
 
+  stopPlaying() {
+    // We emit this so playTrack doesn't immediately start a new track.
+    // We aren't *actually* about to play a new track.
+    this.emit('playing new track')
+    this.player.kill()
+  }
+
   async queueGrouplikeItem(topItem, play = true, afterItem = null) {
     const newTrackIndex = this.queueGrouplike.items.length
 
@@ -367,6 +376,7 @@ class AppElement extends FocusElement {
 
   clearPlayingTrack() {
     this.playingTrack = null
+    this.stopPlaying()
     this.playbackInfoElement.clearInfo()
   }
 }