« get me outta code hell

Make keyboard controls work with caps-lock pressed - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-08-08 19:54:45 -0300
committerFlorrie <towerofnix@gmail.com>2017-08-08 19:54:45 -0300
commit5e90c82c494567a091ff13a632ec34dd33fa9e1b (patch)
treecd96641fbe749d70281dacf8f7de439f360a5814 /src
parentf0758de5069c2958a8efcb2f6e3b0781b77d6ecb (diff)
Make keyboard controls work with caps-lock pressed
Diffstat (limited to 'src')
-rwxr-xr-xsrc/play.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/play.js b/src/play.js
index db7088c..6b9f26c 100755
--- a/src/play.js
+++ b/src/play.js
@@ -348,6 +348,11 @@ async function main(args) {
         Buffer.concat([escModifier, shiftModifier, Buffer.from([num])])
       )
 
+      const equalsChar = char => (
+        Buffer.from(char.toLowerCase()).equals(data) ||
+        Buffer.from(char.toUpperCase()).equals(data)
+      )
+
       if (Buffer.from([0x20]).equals(data)) {
         player.togglePause()
       }
@@ -376,7 +381,7 @@ async function main(args) {
         player.volDown(10)
       }
 
-      if (Buffer.from('s').equals(data)) {
+      if (equalsChar('s')) {
         clearConsoleLine()
         console.log(
           "Skipping the track that's currently playing. " +
@@ -396,15 +401,13 @@ async function main(args) {
         playController.skipUpNext()
       }
 
-      if (
-        Buffer.from('i').equals(data) ||
-        Buffer.from('t').equals(data)
-      ) {
+      if (equalsChar('i') || equalsChar('t')) {
         clearConsoleLine()
         playController.logTrackInfo()
       }
 
       if (
+        equalsChar('q') ||
         Buffer.from('q').equals(data) ||
         Buffer.from([0x03]).equals(data) || // ^C
         Buffer.from([0x04]).equals(data) // ^D