blob: c015ddb09de838951273dd0a25dc25c702c2b5f5 (
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
40
41
42
43
44
|
const ansi = require('../util/ansi')
const Root = require('../ui/Root')
const CommandLineInterfacer = require('../util/CommandLineInterfacer')
const ListScrollForm = require('../ui/form/ListScrollForm')
const Button = require('../ui/form/Button')
const interfacer = new CommandLineInterfacer()
interfacer.getScreenSize().then(size => {
const root = new Root(interfacer)
root.w = size.width
root.h = size.height
const list = new ListScrollForm()
root.addChild(list)
list.x = 2
list.y = 2
list.w = root.contentW - 4
list.h = root.contentH - 4
for (const item of ['Foo', 'Bar', 'Baz']) {
const button = new Button(item)
list.addInput(button)
button.on('pressed', () => {
process.stdout.write(ansi.cleanCursor())
process.stdout.write(ansi.clearScreen())
console.log(item)
process.exit(0)
})
button.fixLayout()
}
list.fixLayout()
root.select(list)
setInterval(() => root.render(), 100)
}).catch(error => {
console.error(error)
process.exit(1)
})
|