Files
bare-operating-system/examples/tui-counter/index.js
T
Raven Scott ddebf42f1c
Release rolling / release (push) Successful in 9m38s
TUI Updates p2
2026-08-12 22:55:38 -04:00

30 lines
801 B
JavaScript

/** Guest TUI counter. Run as a Bare OS script: `run` / `ctx.tui` only. */
async function run(ctx) {
if (!ctx.tui || !ctx.tui.isTTY()) {
ctx.console.error('tui-counter: needs a TTY')
ctx.exitCode = 1
return
}
const app = {
n: 0,
init: function () {
return null
},
update: function (msg) {
if (ctx.tui.key.matches(msg, 'q', 'ctrl+c')) return [this, ctx.tui.quit]
if (ctx.tui.key.matches(msg, 'up', 'k')) this.n++
if (ctx.tui.key.matches(msg, 'down', 'j')) this.n--
return [this, null]
},
view: function () {
return ctx.tui
.style()
.border(ctx.tui.style.borders.rounded)
.padding(1, 2)
.render('count: ' + this.n + '\n\n↑/↓ or k/j change · q quit')
}
}
await ctx.tui.run(app)
}