Skip to content

Commit 8bd26b0

Browse files
authored
fix(watch): clear screen on all terminals (#3661)
1 parent c9aeac4 commit 8bd26b0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/vitest/src/node/logger.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ interface ErrorOptions {
1515
project?: WorkspaceProject
1616
}
1717

18+
const ESC = '\x1B['
19+
const ERASE_DOWN = `${ESC}J`
20+
const ERASE_SCROLLBACK = `${ESC}3J`
21+
const CURSOR_TO_START = `${ESC}1;1H`
22+
const CLEAR_SCREEN = '\x1Bc'
23+
1824
export class Logger {
1925
outputStream = process.stdout
2026
errorStream = process.stderr
@@ -50,7 +56,7 @@ export class Logger {
5056
return
5157
}
5258

53-
this.console.log(`\x1Bc${message}`)
59+
this.console.log(`${ERASE_SCROLLBACK}${CLEAR_SCREEN}${message}`)
5460
}
5561

5662
clearScreen(message: string, force = false) {
@@ -70,9 +76,7 @@ export class Logger {
7076

7177
const log = this._clearScreenPending
7278
this._clearScreenPending = undefined
73-
// equivalent to ansi-escapes:
74-
// stdout.write(ansiEscapes.cursorTo(0, 0) + ansiEscapes.eraseDown + log)
75-
this.console.log(`\u001B[1;1H\u001B[J${log}`)
79+
this.console.log(`${CURSOR_TO_START}${ERASE_DOWN}${log}`)
7680
}
7781

7882
printError(err: unknown, options: ErrorOptions = {}) {

0 commit comments

Comments
 (0)