Skip to content

Commit

Permalink
fix(watch): clear screen on all terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jun 28, 2023
1 parent 6d26b8c commit cc0f4d2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/vitest/src/node/logger.ts
Expand Up @@ -8,6 +8,12 @@ import { RandomSequencer } from './sequencers/RandomSequencer'
import type { Vitest } from './core'
import { printError } from './error'

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 @@ -43,7 +49,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 @@ -63,9 +69,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, fullStack = false, type?: string) {
Expand Down

0 comments on commit cc0f4d2

Please sign in to comment.