Skip to content

Commit

Permalink
fix(watch): clear screen on all terminals (#3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Jul 30, 2023
1 parent c9aeac4 commit 8bd26b0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ interface ErrorOptions {
project?: WorkspaceProject
}

const ESC = '\x1B['
const ERASE_DOWN = `${ESC}J`
const ERASE_SCROLLBACK = `${ESC}3J`
const CURSOR_TO_START = `${ESC}1;1H`
const CLEAR_SCREEN = '\x1Bc'

export class Logger {
outputStream = process.stdout
errorStream = process.stderr
Expand Down Expand Up @@ -50,7 +56,7 @@ export class Logger {
return
}

this.console.log(`\x1Bc${message}`)
this.console.log(`${ERASE_SCROLLBACK}${CLEAR_SCREEN}${message}`)
}

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

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

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

0 comments on commit 8bd26b0

Please sign in to comment.