« get me outta code hell

FocusElement.js « form « ui - 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
blob: 18f13bf000a0dd92a86cb9d5dd62b9ff871359f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const DisplayElement = require('../DisplayElement')

module.exports = class FocusElement extends DisplayElement {
  // A basic element that can receive cursor focus.

  constructor() {
    super()

    this.cursorVisible = false
    this.cursorX = 0
    this.cursorY = 0

    this.isFocused = false
  }

  focused() {
    // Should be overridden in subclasses.

    this.isFocused = true
  }

  unfocused() {
    // Should be overridden in subclasses.

    this.isFocused = 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 }
}