scroll/src/deno/terminal_io.ts

34 lines
757 B
JavaScript
Raw Normal View History

import { ITerminalIO, ITerminalSize } from '../common/types.ts';
2023-11-08 18:07:34 -05:00
const DenoTerminalIO: ITerminalIO = {
/**
* Wrap the runtime-specific hook into stdin
*/
inputLoop: async function* inputLoop(): AsyncGenerator<
Uint8Array,
void,
unknown
> {
for await (const chunk of Deno.stdin.readable) {
yield chunk;
}
},
getSize: function getSize(): ITerminalSize {
const size: { rows: number; columns: number } = Deno.consoleSize();
2023-11-08 18:07:34 -05:00
return {
rows: size.rows,
cols: size.columns,
};
},
write: async function write(s: string): Promise<void> {
const buffer = new TextEncoder().encode(s);
2023-11-08 18:07:34 -05:00
const stdout = Deno.stdout.writable.getWriter();
await stdout.write(buffer);
stdout.releaseLock();
},
};
export default DenoTerminalIO;