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-06 15:36:41 -05:00
|
|
|
/**
|
|
|
|
* Wrap the runtime-specific hook into stdin
|
|
|
|
*/
|
|
|
|
export async function* inputLoop() {
|
|
|
|
for await (const chunk of Deno.stdin.readable) {
|
|
|
|
yield chunk;
|
|
|
|
}
|
|
|
|
}
|
2023-11-08 11:11:19 -05:00
|
|
|
|
|
|
|
export async function write(s: string): Promise<void> {
|
|
|
|
const buffer = new TextEncoder().encode(s);
|
|
|
|
|
|
|
|
const stdout = Deno.stdout.writable.getWriter();
|
|
|
|
await stdout.write(buffer);
|
|
|
|
stdout.releaseLock();
|
|
|
|
}
|
2023-11-08 15:53:14 -05:00
|
|
|
|
2023-11-08 17:02:59 -05:00
|
|
|
export function getSize(): ITerminalSize {
|
|
|
|
const size: { rows: number; columns: number } = Deno.consoleSize();
|
|
|
|
|
|
|
|
return {
|
|
|
|
rows: size.rows,
|
|
|
|
cols: size.columns,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-08 15:53:14 -05:00
|
|
|
const DenoTerminalIO: ITerminalIO = {
|
|
|
|
inputLoop,
|
2023-11-08 17:02:59 -05:00
|
|
|
getSize,
|
2023-11-08 15:53:14 -05:00
|
|
|
write,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DenoTerminalIO;
|