1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix: Use sync ops when clearing the console (#3533)

This commit is contained in:
Nayeem Rahman 2019-12-21 08:58:28 +00:00 committed by Ry Dahl
parent 80da2ac8de
commit f4f4c6bcb4
2 changed files with 7 additions and 7 deletions

View file

@ -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 {

View file

@ -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<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);
});