368
}
369
}
371
>
private _fireChangeEvent() {
372
this._onDidRequestChangeShellIntegration.fire({ terminal: this._terminal, shellIntegration: this.value });
373
}
375
>
376
>
class InternalTerminalShellExecution {
377
>
readonly value: vscode.TerminalShellExecution;
378
>
379
>
private _dataStream: ShellExecutionDataStream | undefined;
380
>
private _isEnded: boolean = false;
381
>
382
>
constructor(
383
>
private _commandLine: vscode.TerminalShellExecutionCommandLine,
384
>
readonly cwd: URI | undefined,
385
>
) {
386
>
const that = this;
387
>
this.value = {
388
>
get commandLine(): vscode.TerminalShellExecutionCommandLine {
389
>
return that._commandLine;
390
>
},
391
>
get cwd(): URI | undefined {
392
return that.cwd;
393
},
395
>
return that._createDataStream();
396
>
}
397
>
};
398
>
}
399
>
400
>
private _createDataStream(): AsyncIterable<string> {
401
>
if (!this._dataStream) {
402
>
if (this._isEnded) {
403
return AsyncIterableObject.EMPTY;
404
}
406
>
}
407
>
return this._dataStream.createIterable();
408
>
}
409
>
410
>
emitData(data: string): void {
411
if (!this._isEnded) {
412
this._dataStream?.emitData(data);
413
}
414
}
416
>
endExecution(commandLine: vscode.TerminalShellExecutionCommandLine | undefined): void {
417
>
if (commandLine) {
418
>
this._commandLine = commandLine;
419
>
}
420
>
this._dataStream?.endExecution();
421
>
this._isEnded = true;
422
>
}
423
>
424
>
async flush(): Promise<void> {
425
>
if (this._dataStream) {
426
>
await this._dataStream.flush();
427
>
this._dataStream.dispose();
428
>
this._dataStream = undefined;
429
>
}
430
>
}
431
>
}
432
>
433
>
class ShellExecutionDataStream extends Disposable {
434
>
private _barrier: Barrier | undefined;
435
>
private _iterables: AsyncIterableObject<string>[] = [];
436
>
private _emitters: AsyncIterableEmitter<string>[] = [];
437
>
438
>
createIterable(): AsyncIterable<string> {
439
>
if (!this._barrier) {
440
>
this._barrier = new Barrier();
441
>
}
442
>
const barrier = this._barrier;
443
>
const iterable = new AsyncIterableObject<string>(async emitter => {
444
>
this._emitters.push(emitter);
445
>
await barrier.wait();
446
>
});
447
>
this._iterables.push(iterable);
448
>
return iterable;
449
>
}
450
>
451
>
emitData(data: string): void {
452
for (const emitter of this._emitters) {
453
emitter.emitOne(data);
454
}
455
}
457
>
endExecution(): void {
458
>
this._barrier?.open();
459
>
}
460
>
461
>
async flush(): Promise<void> {
462
>
await Promise.all(this._iterables.map(e => e.toPromise()));
463
>
}
464
>
}
465
>
466
function splitAndSanitizeCommandLine(commandLine: string): string[] {
467
return commandLine