« get me outta code hell

Initial commit - 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/FocusElement.js
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-01-07 18:26:02 -0400
committerLiam <towerofnix@gmail.com>2017-01-07 18:26:02 -0400
commit16da7fb310198851c2e4b02abedfb24979287242 (patch)
treed7546f7c1a3c3833e6450ea1e10af388f8848bb5 /ui/form/FocusElement.js
Initial commit
Diffstat (limited to 'ui/form/FocusElement.js')
-rw-r--r--ui/form/FocusElement.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/ui/form/FocusElement.js b/ui/form/FocusElement.js
new file mode 100644
index 0000000..25a0693
--- /dev/null
+++ b/ui/form/FocusElement.js
@@ -0,0 +1,38 @@
+const DisplayElement = require('../DisplayElement')
+
+module.exports = class FocusElement extends DisplayElement {
+  // A basic element that can receive cursor focus.
+
+  constructor() {
+    super()
+
+    this.cursorX = 0
+    this.cursorY = 0
+
+    this.isSelected = false
+  }
+
+  focus(socket) {
+    // Do something with socket. Should be overridden in subclasses.
+
+    this.isSelected = true
+  }
+
+  unfocus() {
+    // Should be overridden in subclasses.
+
+    this.isSelected = false
+  }
+
+  keyPressed(keyBuf) {
+    // Do something with a buffer containing the key pressed (that is,
+    // telnet data sent). Should be overridden in subclasses.
+    //
+    // Keyboard characters are sent as a buffer in the form of
+    // ESC[# where # is A, B, C or D. See more here:
+    // http://stackoverflow.com/a/11432632/4633828
+  }
+
+  get absCursorX() { return this.absX + this.cursorX }
+  get absCursorY() { return this.absY + this.cursorY }
+}