FocusBox.js 963 B

123456789101112131415161718192021222324252627282930313233
  1. import {FocusElement} from 'tui-lib/ui/primitives'
  2. import * as ansi from 'tui-lib/util/ansi'
  3. export default class FocusBox extends FocusElement {
  4. // A box (not to be confused with Pane!) that can be selected. When it's
  5. // selected, it applies an invert effect to its children. (This won't work
  6. // well if you have elements inside of it that have their own attributes,
  7. // since they're likely to reset all effects after drawing - including the
  8. // invert from the FocusBox! Bad ANSI limitations; it's relatively likely
  9. // I'll implement maaaaaagic to help deal with this - maybe something
  10. // similar to 'pushMatrix' from Processing - at some point... [TODO])
  11. constructor() {
  12. super()
  13. this.cursorX = null
  14. this.cursorY = null
  15. }
  16. drawTo(writable) {
  17. if (this.isSelected) {
  18. writable.write(ansi.invert())
  19. }
  20. }
  21. didRenderTo(writable) {
  22. if (this.isSelected) {
  23. writable.write(ansi.resetAttributes())
  24. }
  25. }
  26. }