/** 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) }