2023-10-31 14:47:59 -04:00
|
|
|
/**
|
2023-10-31 17:38:15 -04:00
|
|
|
* The main entrypoint when using Bun as the runtime
|
2023-10-31 14:47:59 -04:00
|
|
|
*/
|
2023-10-31 17:38:15 -04:00
|
|
|
|
2023-11-01 15:27:31 -04:00
|
|
|
import { getTermios } from '../common/termios';
|
2023-10-31 17:38:15 -04:00
|
|
|
|
2023-10-31 14:47:59 -04:00
|
|
|
export async function main(): Promise<number> {
|
2023-11-01 15:25:52 -04:00
|
|
|
const t = await getTermios();
|
2023-11-01 14:00:40 -04:00
|
|
|
t.enableRawMode();
|
2023-10-31 17:38:15 -04:00
|
|
|
|
2023-10-31 14:47:59 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
for await (const chunk of Bun.stdin.stream()) {
|
|
|
|
const char = String(decoder.decode(chunk)).trim();
|
|
|
|
|
|
|
|
if (char === 'q') {
|
2023-11-01 14:00:40 -04:00
|
|
|
t.disableRawMode();
|
2023-10-31 14:47:59 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 15:27:31 -04:00
|
|
|
process.on('exit', (code) => {
|
2023-10-31 17:38:15 -04:00
|
|
|
console.log(`Process exited with code ${code}`);
|
2023-11-01 14:00:40 -04:00
|
|
|
t.disableRawMode();
|
2023-10-31 17:38:15 -04:00
|
|
|
});
|
|
|
|
|
2023-10-31 14:47:59 -04:00
|
|
|
return -1;
|
2023-11-01 15:27:31 -04:00
|
|
|
}
|