2023-11-24 08:31:51 -05:00
|
|
|
import { ITerminal, ITerminalSize, readKey } from '../common/runtime.ts';
|
2023-11-08 15:53:14 -05:00
|
|
|
|
2023-11-13 15:33:56 -05:00
|
|
|
const DenoTerminalIO: ITerminal = {
|
|
|
|
argv: Deno.args,
|
2023-11-08 18:07:34 -05:00
|
|
|
/**
|
|
|
|
* Wrap the runtime-specific hook into stdin
|
|
|
|
*/
|
2023-11-10 18:22:09 -05:00
|
|
|
inputLoop: async function* inputLoop() {
|
2023-11-08 18:07:34 -05:00
|
|
|
for await (const chunk of Deno.stdin.readable) {
|
2023-11-24 08:31:51 -05:00
|
|
|
yield readKey(chunk);
|
2023-11-08 18:07:34 -05:00
|
|
|
}
|
|
|
|
},
|
2023-11-10 18:22:09 -05:00
|
|
|
getTerminalSize: function getSize(): Promise<ITerminalSize> {
|
2023-11-08 18:07:34 -05:00
|
|
|
const size: { rows: number; columns: number } = Deno.consoleSize();
|
2023-11-08 17:02:59 -05:00
|
|
|
|
2023-11-10 18:22:09 -05:00
|
|
|
return Promise.resolve({
|
2023-11-08 18:07:34 -05:00
|
|
|
rows: size.rows,
|
|
|
|
cols: size.columns,
|
2023-11-10 18:22:09 -05:00
|
|
|
});
|
2023-11-08 18:07:34 -05:00
|
|
|
},
|
2023-11-13 15:33:56 -05:00
|
|
|
writeStdout: async function write(s: string): Promise<void> {
|
2023-11-10 18:22:09 -05:00
|
|
|
const buffer: Uint8Array = new TextEncoder().encode(s);
|
|
|
|
const stdout: WritableStream<Uint8Array> = Deno.stdout.writable;
|
2023-11-08 17:02:59 -05:00
|
|
|
|
2023-11-10 18:22:09 -05:00
|
|
|
const writer: WritableStreamDefaultWriter<Uint8Array> = stdout.getWriter();
|
|
|
|
await writer.ready;
|
|
|
|
await writer.write(buffer);
|
|
|
|
writer.releaseLock();
|
2023-11-08 18:07:34 -05:00
|
|
|
},
|
2023-11-08 15:53:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DenoTerminalIO;
|