From f4f4c6bcb435ffb7e1dd9383d8d39e9e36b1337a Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 21 Dec 2019 08:58:28 +0000 Subject: [PATCH] fix: Use sync ops when clearing the console (#3533) --- cli/js/console.ts | 4 ++-- cli/js/console_test.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/js/console.ts b/cli/js/console.ts index adebd729f1..216741a5e0 100644 --- a/cli/js/console.ts +++ b/cli/js/console.ts @@ -40,12 +40,12 @@ export class CSI { function cursorTo(stream: File, _x: number, _y?: number): void { const uint8 = new TextEncoder().encode(CSI.kClear); - stream.write(uint8); + stream.writeSync(uint8); } function clearScreenDown(stream: File): void { const uint8 = new TextEncoder().encode(CSI.kClearScreenDown); - stream.write(uint8); + stream.writeSync(uint8); } function getClassInstanceName(instance: unknown): string { diff --git a/cli/js/console_test.ts b/cli/js/console_test.ts index e7c5971cdf..4edc4aec66 100644 --- a/cli/js/console_test.ts +++ b/cli/js/console_test.ts @@ -8,7 +8,7 @@ const { customInspect, stringifyArgs, inspect, - write, + writeSync, stdout // eslint-disable-next-line @typescript-eslint/no-explicit-any } = Deno as any; @@ -331,20 +331,20 @@ test(function consoleTestError(): void { }); test(function consoleTestClear(): void { - const stdoutWrite = stdout.write; + const stdoutWriteSync = stdout.writeSync; const uint8 = new TextEncoder().encode("\x1b[1;1H" + "\x1b[0J"); let buffer = new Uint8Array(0); - stdout.write = async (u8: Uint8Array): Promise => { + stdout.writeSync = (u8: Uint8Array): Promise => { const tmp = new Uint8Array(buffer.length + u8.length); tmp.set(buffer, 0); tmp.set(u8, buffer.length); buffer = tmp; - return await write(stdout.rid, u8); + return writeSync(stdout.rid, u8); }; console.clear(); - stdout.write = stdoutWrite; + stdout.writeSync = stdoutWriteSync; assertEquals(buffer, uint8); });