Skip to content

Commit

Permalink
fix: Use sync ops when clearing the console (denoland#3533)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn authored and ry committed Dec 21, 2019
1 parent 80da2ac commit f4f4c6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cli/js/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions cli/js/console_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
customInspect,
stringifyArgs,
inspect,
write,
writeSync,
stdout
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} = Deno as any;
Expand Down Expand Up @@ -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<number> => {
stdout.writeSync = (u8: Uint8Array): Promise<number> => {
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);
});

Expand Down

0 comments on commit f4f4c6b

Please sign in to comment.