mirror of
https://github.com/denoland/deno.git
synced 2025-01-10 08:09:06 -05:00
fix: Use sync ops when clearing the console (#3533)
This commit is contained in:
parent
80da2ac8de
commit
f4f4c6bcb4
2 changed files with 7 additions and 7 deletions
|
@ -40,12 +40,12 @@ export class CSI {
|
||||||
|
|
||||||
function cursorTo(stream: File, _x: number, _y?: number): void {
|
function cursorTo(stream: File, _x: number, _y?: number): void {
|
||||||
const uint8 = new TextEncoder().encode(CSI.kClear);
|
const uint8 = new TextEncoder().encode(CSI.kClear);
|
||||||
stream.write(uint8);
|
stream.writeSync(uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearScreenDown(stream: File): void {
|
function clearScreenDown(stream: File): void {
|
||||||
const uint8 = new TextEncoder().encode(CSI.kClearScreenDown);
|
const uint8 = new TextEncoder().encode(CSI.kClearScreenDown);
|
||||||
stream.write(uint8);
|
stream.writeSync(uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClassInstanceName(instance: unknown): string {
|
function getClassInstanceName(instance: unknown): string {
|
||||||
|
|
|
@ -8,7 +8,7 @@ const {
|
||||||
customInspect,
|
customInspect,
|
||||||
stringifyArgs,
|
stringifyArgs,
|
||||||
inspect,
|
inspect,
|
||||||
write,
|
writeSync,
|
||||||
stdout
|
stdout
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
} = Deno as any;
|
} = Deno as any;
|
||||||
|
@ -331,20 +331,20 @@ test(function consoleTestError(): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function consoleTestClear(): void {
|
test(function consoleTestClear(): void {
|
||||||
const stdoutWrite = stdout.write;
|
const stdoutWriteSync = stdout.writeSync;
|
||||||
const uint8 = new TextEncoder().encode("\x1b[1;1H" + "\x1b[0J");
|
const uint8 = new TextEncoder().encode("\x1b[1;1H" + "\x1b[0J");
|
||||||
let buffer = new Uint8Array(0);
|
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);
|
const tmp = new Uint8Array(buffer.length + u8.length);
|
||||||
tmp.set(buffer, 0);
|
tmp.set(buffer, 0);
|
||||||
tmp.set(u8, buffer.length);
|
tmp.set(u8, buffer.length);
|
||||||
buffer = tmp;
|
buffer = tmp;
|
||||||
|
|
||||||
return await write(stdout.rid, u8);
|
return writeSync(stdout.rid, u8);
|
||||||
};
|
};
|
||||||
console.clear();
|
console.clear();
|
||||||
stdout.write = stdoutWrite;
|
stdout.writeSync = stdoutWriteSync;
|
||||||
assertEquals(buffer, uint8);
|
assertEquals(buffer, uint8);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue