From f6d93d115144004caaa16fa274afe6fcf801ba5a Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 7 Mar 2024 00:27:59 +0100 Subject: [PATCH] replace the homemade `clearAnsiEscapes` with the native `stripVTControlCharacters` (#13117) --- packages/@tailwindcss-cli/src/utils/renderer.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/@tailwindcss-cli/src/utils/renderer.ts b/packages/@tailwindcss-cli/src/utils/renderer.ts index a38986976..35365e8ba 100644 --- a/packages/@tailwindcss-cli/src/utils/renderer.ts +++ b/packages/@tailwindcss-cli/src/utils/renderer.ts @@ -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. */