Something went wrong. Try again.
Measure the width of text in the terminal and build simple layouts!
Something went wrong. Try again.
710 B · 32 lines
JavaScript
at main
123456789101112131415161718192021222324252627282930313233export function tui_app(state, on_resize, on_data, view) { const stdin = process.stdin; const stdout = process.stdout; stdin.setRawMode(true); stdin.setEncoding('utf8');
function render() { stdout.write(view(state)) }
stdin.on('data', function(key) { if (key === '\x03' || key === 'q') { stdout.write("\x1b[?1049l"); process.exit() } state = on_data(state, key); render() })
stdin.on('resize', function() { state = on_resize(state, stdin.rows, stdin.columns) render() }) stdout.on('resize', function() { state = on_resize(state, stdout.rows, stdout.columns) render() })
stdout.write("\x1b[?1049h"); render() stdin.resume();}