Use Node stdin API for Bun to allow basic functionality to work again
timw4mail/scroll/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2024-03-01 11:28:34 -05:00
parent ab42873182
commit 9d45cf9296
1 changed files with 10 additions and 3 deletions

View File

@ -7,6 +7,8 @@ import { defaultTerminalSize } from '../common/config.ts';
import { readKey } from '../common/fns.ts';
import { ITerminal, ITerminalSize } from '../common/types.ts';
const encoder = new TextEncoder();
async function _getTerminalSizeFromAnsi(): Promise<ITerminalSize> {
// Tell the cursor to move to Row 999 and Column 999
// Since this command specifically doesn't go off the screen
@ -46,8 +48,13 @@ const BunTerminalIO: ITerminal = {
// to have consistent argument lists
argv: (Bun.argv.length > 2) ? Bun.argv.slice(2) : [],
inputLoop: async function* inputLoop() {
for await (const chunk of Bun.stdin.stream()) {
yield chunk;
// for await (const chunk of Bun.stdin.stream()) {
// yield chunk;
// }
//
// return null;
for await (const chunk of process.stdin) {
yield encoder.encode(chunk);
}
return null;
@ -73,7 +80,7 @@ const BunTerminalIO: ITerminal = {
return chunk.value ?? null;
},
writeStdout: async function write(s: string): Promise<void> {
const buffer = new TextEncoder().encode(s);
const buffer = encoder.encode(s);
await Bun.write(Bun.stdout, buffer);
},