-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathcustomBuildTask.ts
More file actions
74 lines (64 loc) · 2.04 KB
/
Copy pathcustomBuildTask.ts
File metadata and controls
74 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as vscode from 'vscode';
import * as util from '../util';
import { getCurPID } from '../make';
abstract class CommandConsumer {
output(line: string): void {
this._stdout.push(line);
}
error(error: string): void {
this._stderr.push(error);
}
get stdout() {
return this._stdout.join('\n');
}
protected readonly _stdout = new Array<string>();
get stderr() {
return this._stderr.join('\n');
}
protected readonly _stderr = new Array<string>();
}
const endOfLine: string = "\r\n";
export class CustomBuildTaskTerminal extends CommandConsumer implements vscode.Pseudoterminal {
constructor(private command: string, private args: string[], private cwd: string, private env?: { [key: string]: string }) {
super();
}
private writeEmitter = new vscode.EventEmitter<string>();
private closeEmitter = new vscode.EventEmitter<number>();
public get onDidWrite(): vscode.Event<string> {
return this.writeEmitter.event;
}
public get onDidClose(): vscode.Event<number> {
return this.closeEmitter.event;
}
override output(line: string): void {
this.writeEmitter.fire(line + endOfLine);
super.output(line);
}
override error(error: string): void {
this.writeEmitter.fire(error + endOfLine);
super.error(error);
}
private _process: util.SpawnProcess | undefined;
async open(_initialDimensions: vscode.TerminalDimensions | undefined): Promise<void> {
this._process = util.spawnChildProcess(
this.command,
this.args,
{
workingDirectory: this.cwd,
stdoutCallback: (line: string) => this.output(line),
stderrCallback: (error: string) => this.error(error),
env: this.env
}
)
const res: util.SpawnProcessResult = await this._process.result;
this.closeEmitter.fire(res.returnCode);
}
async close(): Promise<void> {
if (this._process) {
if (this._process.child) {
await util.killTree(getCurPID());
}
this._process = undefined;
}
}
}