scroll/src/bun/terminal_io.ts

30 lines
742 B
JavaScript
Raw Normal View History

/**
* Wrap the runtime-specific hook into stdin
*/
import { ITerminalIO, ITerminalSize } from '../common/mod.ts';
2023-11-08 18:07:34 -05:00
const BunTerminalIO: ITerminalIO = {
inputLoop: async function* inputLoop() {
for await (const chunk of Bun.stdin.stream()) {
yield chunk;
}
},
getSize: function getSize(): ITerminalSize {
// @TODO implement
// Check for tput
// If has tput, use it to get terminal size
// If not, try FFI fallback
// Otherwise, return 80x25 as a last resort
const fallback: ITerminalSize = { rows: 25, cols: 80 };
2023-11-08 18:07:34 -05:00
return fallback;
},
write: async function write(s: string): Promise<void> {
const buffer = new TextEncoder().encode(s);
2023-11-08 18:07:34 -05:00
await Bun.write(Bun.stdout, buffer);
},
};
export default BunTerminalIO;