scroll/src/bun/index.ts

26 lines
514 B
JavaScript
Raw Normal View History

2023-10-31 14:47:59 -04:00
/**
* The main entrypoint when using Bun as the runtime
2023-10-31 14:47:59 -04:00
*/
import {enableRawMode} from './ffi'
2023-10-31 14:47:59 -04:00
export async function main(): Promise<number> {
const disableRawMode = enableRawMode();
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') {
disableRawMode();
2023-10-31 14:47:59 -04:00
return 0;
}
}
process.on("exit", (code) => {
console.log(`Process exited with code ${code}`);
disableRawMode();
});
2023-10-31 14:47:59 -04:00
return -1;
}