mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
parent
267b98d271
commit
00b145c091
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue