« get me outta code hell

Jump to menubar options with keyboard - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-09-20 17:06:03 -0300
committerFlorrie <towerofnix@gmail.com>2019-09-20 17:06:03 -0300
commit571026560ec61e26c4498f3d7e9a982c9b5aa68e (patch)
tree8f55c50aa8b6ddbd677f585fefaca8556ea38f82
parent6bad90e8e0db9c9273de984be53a1ca61b4d8a24 (diff)
Jump to menubar options with keyboard
I _love_ the KeyboardSelector tool.
-rw-r--r--todo.txt6
-rw-r--r--ui.js13
2 files changed, 15 insertions, 4 deletions
diff --git a/todo.txt b/todo.txt
index 9e03156..fc57067 100644
--- a/todo.txt
+++ b/todo.txt
@@ -407,3 +407,9 @@ TODO: Investigate why reveal() has distinct support for grouplikes as well as
 TODO: Make the menubar work like context menus for keyboard selection, e.g.
       pressing P should select 'Playback' (not bubble to the app element and
       rewind to the previous track).
+      (Done!)
+
+TODO: Implement a UI in the playback info pane that shows when multiple players
+      exist at once. Make sure it's mouse-interactive, too!
+
+TODO: Add a menu for controlling the multiple-players code through the menubar.
diff --git a/ui.js b/ui.js
index de3ab98..d70bc31 100644
--- a/ui.js
+++ b/ui.js
@@ -3355,6 +3355,8 @@ class Menubar extends ListScrollForm {
     this.contextMenu = null
     this.color = 4 // blue
     this.attribute = 2 // dim
+
+    this.keyboardSelector = new KeyboardSelector(this)
   }
 
   select() {
@@ -3370,6 +3372,7 @@ class Menubar extends ListScrollForm {
     }
 
     this.root.select(this)
+    this.keyboardSelector.reset()
   }
 
   keyPressed(keyBuf) {
@@ -3380,12 +3383,13 @@ class Menubar extends ListScrollForm {
       return false
     }
 
-    // For fun :)
-    if (telc.isCaselessLetter(keyBuf, 'c')) {
+    if (this.keyboardSelector.keyPressed(keyBuf)) {
+      return false
+    } else if (telc.isCaselessLetter(keyBuf, 'c')) {
+      // For fun :)
       this.color = (this.color % 8) + 1
       return false
-    }
-    if (telc.isCaselessLetter(keyBuf, 'a')) {
+    } else if (telc.isCaselessLetter(keyBuf, 'a')) {
       this.attribute = (this.attribute % 3) + 1
       return false
     }
@@ -3408,6 +3412,7 @@ class Menubar extends ListScrollForm {
       container.w = button.w + 2
       container.h = 1
       container.selected = () => this.root.select(button)
+      container.keyboardIdentifier = text
 
       button.on('pressed', () => {
         this.contextMenu = this.showContextMenu({