Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(watch): clear screen on all terminals #3661

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
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