« get me outta code hell

FocusBox.js « controls « 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/controls/FocusBox.js
blob: 64f84c90be935d79775aae1db988ce9bc257520d (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
import {FocusElement} from 'tui-lib/ui/primitives'

import * as ansi from 'tui-lib/util/ansi'

export default 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())
    }
  }
}