« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--todo.txt4
-rw-r--r--ui/form/ListScrollForm.js38
3 files changed, 24 insertions, 20 deletions
diff --git a/package.json b/package.json
index 33f58c8..b2d3cb2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tui-lib",
-  "version": "0.1.1",
+  "version": "0.2.1",
   "description": "terminal ui library",
   "main": "index.js",
   "repository": "https://notabug.org/towerofnix/tui-lib.git",
diff --git a/todo.txt b/todo.txt
new file mode 100644
index 0000000..6a0fffc
--- /dev/null
+++ b/todo.txt
@@ -0,0 +1,4 @@
+TODO: Figure out why the text cursor is positioned differently when using
+      ANSI compression.
+
+TODO: Horizontal scroll-bars.
diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js
index 72e79df..e4f4249 100644
--- a/ui/form/ListScrollForm.js
+++ b/ui/form/ListScrollForm.js
@@ -15,6 +15,7 @@ module.exports = class ListScrollForm extends Form {
     super()
 
     this.layoutType = layoutType
+    this.wheelMode = 'scroll' // scroll, selection
 
     this.scrollItems = 0
 
@@ -122,27 +123,26 @@ module.exports = class ListScrollForm extends Form {
   }
 
   clicked(button) {
-    // Old code for changing the actual selected item...maybe an interesting
-    // functionality to explore later?
-    /*
-    if (button === 'scroll-up') {
-      this.previousInput()
-      this.scrollSelectedElementIntoView()
-    } else if (button === 'scroll-down') {
-      this.nextInput()
-      this.scrollSelectedElementIntoView()
-    }
-    */
-
-    // Scrolling is typically pretty slow with a mouse wheel when it's by
-    // a single line, so scroll at 3x that speed.
-    for (let i = 0; i < 3; i++) {
+    if (this.wheelMode === 'selection') {
+      // Change the actual selected item.
       if (button === 'scroll-up') {
-        this.scrollItems--
+        this.previousInput()
+        this.scrollSelectedElementIntoView()
       } else if (button === 'scroll-down') {
-        this.scrollItems++
-      } else {
-        return
+        this.nextInput()
+        this.scrollSelectedElementIntoView()
+      }
+    } else if (this.wheelMode === 'scroll') {
+      // Scrolling is typically pretty slow with a mouse wheel when it's by
+      // a single line, so scroll at 3x that speed.
+      for (let i = 0; i < 3; i++) {
+        if (button === 'scroll-up') {
+          this.scrollItems--
+        } else if (button === 'scroll-down') {
+          this.scrollItems++
+        } else {
+          return
+        }
       }
     }