« get me outta code hell

FocusBox.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/FocusBox.js
blob: 69b5bf5615212b89448c3979598a2bdd6090d3b7 (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
const ansi = require('../../util/ansi')

const FocusElement = require('./FocusElement')

module.exports = class FocusBox extends FocusElement {
  // A box (not to be confused with Pane!) that can be selected. When it's
  // selected, it applies an invert effect to its children. (This won't work
  // well if you have elements inside of it that have their own attributes,
  // since they're likely to reset all effects after drawing - including the
  // invert from the FocusBox! Bad ANSI limitations; it's relatively likely
  // I'll implement maaaaaagic to help deal with this - maybe something
  // similar to 'pushMatrix' from Processing - at some point... [TODO])

  constructor() {
    super()

    this.cursorX = null
    this.cursorY = null
  }

  drawTo(writable) {
    if (this.isSelected) {
      writable.write(ansi.invert())
    }
  }

  didRenderTo(writable) {
    if (this.isSelected) {
      writable.write(ansi.resetAttributes())
    }
  }
}