/** * The main entrypoint when using Bun as the runtime */ import { getTermios } from '../common/termios'; import {ctrl_key, is_control} from "../common/strings"; export async function main(): Promise { const t = await getTermios(); t.enableRawMode(); const decoder = new TextDecoder(); for await (const chunk of Bun.stdin.stream()) { const char = String(decoder.decode(chunk)); if (char === ctrl_key('q')) { t.disableRawMode(); return 0; } if (is_control(char)) { console.log(char.codePointAt(0) + '\r'); } else { console.log(`${char} ('${char.codePointAt(0)}')\r`); } } process.on('exit', (code) => { console.log(`Process exited with code ${code}`); t.disableRawMode(); }); return -1; }