list-scroll-form.js 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {Root} from 'tui-lib/ui/primitives'
  2. import {Button, ListScrollForm} from 'tui-lib/ui/controls'
  3. import {CommandLineInterface} from 'tui-lib/util/interfaces'
  4. import * as ansi from 'tui-lib/util/ansi'
  5. const clInterface = new CommandLineInterface()
  6. clInterface.getScreenSize().then(size => {
  7. const root = new Root(clInterface)
  8. root.w = size.width
  9. root.h = size.height
  10. const list = new ListScrollForm()
  11. root.addChild(list)
  12. list.x = 2
  13. list.y = 2
  14. list.w = root.contentW - 4
  15. list.h = root.contentH - 4
  16. for (const item of ['Foo', 'Bar', 'Baz']) {
  17. const button = new Button(item)
  18. list.addInput(button)
  19. button.on('pressed', () => {
  20. process.stdout.write(ansi.cleanCursor())
  21. process.stdout.write(ansi.clearScreen())
  22. console.log(item)
  23. process.exit(0)
  24. })
  25. button.fixLayout()
  26. }
  27. list.fixLayout()
  28. root.select(list)
  29. setInterval(() => root.render(), 100)
  30. }).catch(error => {
  31. console.error(error)
  32. process.exit(1)
  33. })