« get me outta code hell

Add Dialog.js file, apparently - 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
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-12-09 17:23:56 -0400
committerFlorrie <towerofnix@gmail.com>2017-12-09 17:23:56 -0400
commit0c58ec6048c282c7c0ae22ebfe2860f2cef40df5 (patch)
treeb7e243494b464abf58e49c641cb67920f9798d20 /ui
parentb83766c92658228e3fb695ffd61b97461216780f (diff)
Add Dialog.js file, apparently
Diffstat (limited to 'ui')
-rw-r--r--ui/Dialog.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/ui/Dialog.js b/ui/Dialog.js
new file mode 100644
index 0000000..26d94d8
--- /dev/null
+++ b/ui/Dialog.js
@@ -0,0 +1,37 @@
+const FocusElement = require('./form/FocusElement')
+
+const Pane = require('./Pane')
+
+const telc = require('../util/telchars')
+
+module.exports = class Dialog extends FocusElement {
+  // A simple base dialog.
+  //
+  // Emits the 'cancelled' event when the cancel key (escape) is pressed,
+  // which should (probably) be handled by the dialog's creator.
+  //
+  // Doesn't do anything when focused by default - this should be overridden
+  // in subclasses.
+  //
+  // Automatically adjusts to fill its parent. Has a pane child (this.pane),
+  // but the pane isn't adjusted at all (you should change its size and
+  // likely center it in your subclass).
+
+  constructor() {
+    super()
+
+    this.pane = new Pane()
+    this.addChild(this.pane)
+  }
+
+  fixLayout() {
+    this.w = this.parent.contentW
+    this.h = this.parent.contentH
+  }
+
+  keyPressed(keyBuf) {
+    if (telc.isCancel(keyBuf)) {
+      this.emit('cancelled')
+    }
+  }
+}