replace the homemade clearAnsiEscapes with the native stripVTControlCharacters (#13117)

This commit is contained in:
Robin Malfait 2024-03-07 00:27:59 +01:00 • committed by GitHub
parent e2dcbad153
commit f6d93d1151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { stripVTControlCharacters } from 'node:util'
import pc from 'picocolors'
import { resolve } from '../utils/resolve'
import { formatNanoseconds } from './format-ns'
@ -48,7 +49,7 @@ export function wordWrap(text: string, width: number) {
let line = ''
let lineLength = 0
for (let word of words) {
let wordLength = clearAnsiEscapes(word).length
let wordLength = stripVTControlCharacters(word).length
if (lineLength + wordLength + 1 > width) {
lines.push(line)
@ -67,11 +68,6 @@ export function wordWrap(text: string, width: number) {
return lines
}
const ESCAPE = /((?:\x9B|\x1B\[)[0-?]*[ -\/]*[@-~])/g
function clearAnsiEscapes(input: string) {
return input.replace(ESCAPE, '')
}
/**
* Format a duration in nanoseconds to a more human readable format.
*/