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 26, 2023
1 parent fbb56ad commit 9ef1a4a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion 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'

// https://www.real-world-systems.com/docs/ANSIcode.html
const ESC = '\x1B['
const ERASE_SCREEN = `${ESC}2J`
const ERASE_SCROLLBACK = `${ESC}3J`
const CURSOR_HOME_ROW = `${ESC}H`

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

this.console.log(`\x1Bc${message}`)
// Clear screen and scrollback buffer. Windows requires special handling except on Git Bash
if (process.platform === 'win32' && !process.env.SHELL?.includes('bash'))
this.console.log(`${ERASE_SCREEN}${ESC}0f`)
else
this.console.log(`${ERASE_SCREEN}${ERASE_SCROLLBACK}${CURSOR_HOME_ROW}`)

this.console.log(message)
}

clearScreen(message: string, force = false) {
Expand Down

0 comments on commit 9ef1a4a

Please sign in to comment.