diff --git a/justfile b/justfile index 095ab32..1874b09 100644 --- a/justfile +++ b/justfile @@ -9,6 +9,10 @@ deno-lint: # Code linting with bun bun-lint: +# Run with bun +bun-run: + bun run ./src/scroll.ts + # Run with deno deno-run: deno run --allow-all --allow-ffi --deny-net --deny-hrtime --unstable ./src/scroll.ts \ No newline at end of file diff --git a/src/bun/index.ts b/src/bun/index.ts new file mode 100644 index 0000000..b2dfafa --- /dev/null +++ b/src/bun/index.ts @@ -0,0 +1,15 @@ +/** + * The main entrypoint when using Deno as the runtime + */ +export async function main(): Promise { + const decoder = new TextDecoder(); + for await (const chunk of Bun.stdin.stream()) { + const char = String(decoder.decode(chunk)).trim(); + + if (char === 'q') { + return 0; + } + } + + return -1; +} \ No newline at end of file diff --git a/src/scroll.ts b/src/scroll.ts index 806a26a..2973721 100644 --- a/src/scroll.ts +++ b/src/scroll.ts @@ -15,10 +15,11 @@ export enum RunTime { let RUNTIME = RunTime.Unknown; if ('Deno' in globalThis) { RUNTIME = RunTime.Deno; - const { main } = await import('./deno/index.ts'); - await main(); } if ('Bun' in globalThis) { RUNTIME = RunTime.Bun; } + + const { main } = await import(`./${RUNTIME}/index.ts`); + await main(); })();