mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
strings: use more comprehensive ansi escape code regex (#173362)
* strings: use more comprehensive ansi escape code regex The ansi escape remover only recognized a few codes, and only a subset of their syntax. Be more comprehensive, and add tests. Fixes #153648 * address pr comment
This commit is contained in:
@@ -21,11 +21,8 @@ interface ServerReadyAction {
|
||||
killOnServerStop?: boolean;
|
||||
}
|
||||
|
||||
// Escape codes
|
||||
// http://en.wikipedia.org/wiki/ANSI_escape_code
|
||||
const EL = /\x1B\x5B[12]?K/g; // Erase in line
|
||||
const COLOR_START = /\x1b\[\d+m/g; // Color
|
||||
const COLOR_END = /\x1b\[0?m/g; // Color
|
||||
// Escape codes, compiled from https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
|
||||
const CSI_SEQUENCE = /(:?\x1b\[|\x9B)[=?>!]?[\d;:]*["$#'* ]?[a-zA-Z@^`{}|~]/g;
|
||||
|
||||
/**
|
||||
* Froms vs/base/common/strings.ts in core
|
||||
@@ -33,9 +30,7 @@ const COLOR_END = /\x1b\[0?m/g; // Color
|
||||
*/
|
||||
function removeAnsiEscapeCodes(str: string): string {
|
||||
if (str) {
|
||||
str = str.replace(EL, '');
|
||||
str = str.replace(COLOR_START, '');
|
||||
str = str.replace(COLOR_END, '');
|
||||
str = str.replace(CSI_SEQUENCE, '');
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
Reference in New Issue
Block a user