Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use sync ops when clearing the console #3533

Merged
merged 2 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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