Capture all OSC sequences and ESC sequences

Part of microsoft/vscode-copilot#14072
This commit is contained in:
Daniel Imms
2025-03-11 12:54:12 -07:00
parent 856dbe90b0
commit e9f1d10a3a
3 changed files with 219 additions and 136 deletions

View File

@@ -23,7 +23,14 @@ interface ServerReadyAction {
}
// From src/vs/base/common/strings.ts
const CSI_SEQUENCE = /(?:(?:\x1b\[|\x9B)[=?>!]?[\d;:]*["$#'* ]?[a-zA-Z@^`{}|~])|(:?\x1b\].*?\x07)/g;
const CSI_SEQUENCE = /(?:\x1b\[|\x9b)[=?>!]?[\d;:]*["$#'* ]?[a-zA-Z@^`{}|~]/;
const OSC_SEQUENCE = /(?:\x1b\]|\x9d).*?(?:\x1b\\|\x07|\x9c)/;
const ESC_SEQUENCE = /\x1b(?:[ #%\(\)\*\+\-\.\/]?[a-zA-Z0-9\|}~@])/;
const CONTROL_SEQUENCES = new RegExp('(?:' + [
CSI_SEQUENCE.source,
OSC_SEQUENCE.source,
ESC_SEQUENCE.source,
].join('|') + ')', 'g');
/**
* Froms vs/base/common/strings.ts in core
@@ -31,7 +38,7 @@ const CSI_SEQUENCE = /(?:(?:\x1b\[|\x9B)[=?>!]?[\d;:]*["$#'* ]?[a-zA-Z@^`{}|~])|
*/
function removeAnsiEscapeCodes(str: string): string {
if (str) {
str = str.replace(CSI_SEQUENCE, '');
str = str.replace(CONTROL_SEQUENCES, '');
}
return str;