diff --git a/extensions/debug-server-ready/src/extension.ts b/extensions/debug-server-ready/src/extension.ts index 592dec936eb..035566a4ba5 100644 --- a/extensions/debug-server-ready/src/extension.ts +++ b/extensions/debug-server-ready/src/extension.ts @@ -21,6 +21,26 @@ 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 + +/** + * Froms vs/base/common/strings.ts in core + * @see https://github.com/microsoft/vscode/blob/22a2a0e833175c32a2005b977d7fbd355582e416/src/vs/base/common/strings.ts#L736 + */ +function removeAnsiEscapeCodes(str: string): string { + if (str) { + str = str.replace(EL, ''); + str = str.replace(COLOR_START, ''); + str = str.replace(COLOR_END, ''); + } + + return str; +} + class Trigger { private _fired = false; @@ -77,16 +97,17 @@ class ServerReadyDetector extends vscode.Disposable { // first find the detector with a matching pid const pid = await e.terminal.processId; + const str = removeAnsiEscapeCodes(e.data); for (const [, detector] of this.detectors) { if (detector.shellPid === pid) { - detector.detectPattern(e.data); + detector.detectPattern(str); return; } } // if none found, try all detectors until one matches for (const [, detector] of this.detectors) { - if (detector.detectPattern(e.data)) { + if (detector.detectPattern(str)) { return; } }