« 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/examples
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 /examples
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 'examples')
-rw-r--r--examples/list-scroll-form.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/list-scroll-form.js b/examples/list-scroll-form.js
new file mode 100644
index 0000000..a68cb78
--- /dev/null
+++ b/examples/list-scroll-form.js
@@ -0,0 +1,42 @@
+const ansi = require('../util/ansi')
+const Root = require('../ui/Root')
+const CommandLineInterfacer = require('../util/CommandLineInterfacer')
+const ListScrollForm = require('../ui/form/ListScrollForm')
+const Button = require('../ui/form/Button')
+
+const interfacer = new CommandLineInterfacer()
+
+interfacer.getScreenSize().then(size => {
+  const root = new Root(interfacer)
+  root.w = size.width
+  root.h = size.height
+
+  const list = new ListScrollForm()
+  root.addChild(list)
+  list.x = 2
+  list.y = 2
+  list.w = root.contentW - 4
+  list.h = root.contentH - 4
+
+  for (let item of ['Foo', 'Bar', 'Baz']) {
+    const button = new Button(item)
+    list.addInput(button)
+
+    button.on('pressed', () => {
+      process.stdout.write(ansi.clearScreen())
+      console.log(item)
+      process.exit(0)
+    })
+
+    button.fixLayout()
+  }
+
+  list.fixLayout()
+
+  root.select(list)
+
+  setInterval(() => root.render(), 100)
+}).catch(error => {
+  console.error(error)
+  process.exit(1)
+})