« get me outta code hell

Buttons and lists - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/ui/form/ListScrollForm.js
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-07-03 21:00:02 -0300
committerliam4 <towerofnix@gmail.com>2017-07-03 21:00:02 -0300
commit930d61b9f067346f467d4d84015088f57c54da56 (patch)
treef96e81b861feb74e1a929360946818787d0ee7e0 /ui/form/ListScrollForm.js
parent769413468e88acba1a180baa0113139d929a3b9f (diff)
Buttons and lists
- Button class name changed to Button, from ButtonInput
- Button layouts are now updated with fixLayout, rather than
  automatically when the text property is changed
- Buttons now have a height of 1, so they can generally actually
  be used in layouts

- New example for list form elements
- List form elements let you navigate with up/down (or left/right,
  for horizontal lists)
- List forms now have nextInput and previousInput methods
Diffstat (limited to 'ui/form/ListScrollForm.js')
-rw-r--r--ui/form/ListScrollForm.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js
index b1484b5..b23f973 100644
--- a/ui/form/ListScrollForm.js
+++ b/ui/form/ListScrollForm.js
@@ -1,3 +1,5 @@
+const telc = require('../../util/telchars')
+
 const Form = require('./Form')
 
 module.exports = class ListScrollForm extends Form {
@@ -44,7 +46,27 @@ module.exports = class ListScrollForm extends Form {
   }
 
   keyPressed(keyBuf) {
-    super.keyPressed(keyBuf)
+    handleKeyPress: {
+      if (this.layoutType === 'horizontal') {
+        if (telc.isLeft(keyBuf)) {
+          this.previousInput()
+          break handleKeyPress
+        } else if (telc.isRight(keyBuf)) {
+          this.nextInput()
+          break handleKeyPress
+        }
+      } else if (this.layoutType === 'vertical') {
+        if (telc.isUp(keyBuf)) {
+          this.previousInput()
+          break handleKeyPress
+        } else if (telc.isDown(keyBuf)) {
+          this.nextInput()
+          break handleKeyPress
+        }
+      }
+
+      super.keyPressed(keyBuf)
+    }
 
     const sel = this.inputs[this.curIndex]