2023-11-08 17:02:59 -05:00
|
|
|
import { ITerminalIO, ITerminalSize } from '../common/types.ts';
|
2023-11-08 15:53:14 -05:00
|
|
|
|
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 17:02:59 -05:00
|
|
|
|
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 17:02:59 -05:00
|
|
|
|
2023-11-08 18:07:34 -05:00
|
|
|
const stdout = Deno.stdout.writable.getWriter();
|
|
|
|
await stdout.write(buffer);
|
|
|
|
stdout.releaseLock();
|
|
|
|
},
|
2023-11-08 15:53:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DenoTerminalIO;
|