11import * as vscode from 'vscode' ;
2- import { spawn , type ChildProcessWithoutNullStreams } from 'node:child_process' ;
2+ import { type ChildProcessWithoutNullStreams } from 'node:child_process' ;
33
44import { EventWaiter } from '../util/EventWaiter' ;
5- import { getEnvConfig } from '../config/config' ;
6- import { getErrorsFromStdOut , removePrefixFromStdOut } from '../cli/ef' ;
5+ import { CLI } from '../cli/CLI' ;
76
87const NL = '\n' ;
98const CR = '\r' ;
109const nlRegExp = new RegExp ( `${ NL } ([^${ CR } ]|$)` , 'g' ) ;
1110
1211export class Terminal implements vscode . Pseudoterminal {
1312 private cmdArgs : string [ ] = [ ] ;
13+ private cmdParams : { [ key : string ] : string } = { } ;
1414 private cmd : ChildProcessWithoutNullStreams | undefined ;
1515
1616 private readonly writeEmitter = new vscode . EventEmitter < string > ( ) ;
@@ -23,58 +23,33 @@ export class Terminal implements vscode.Pseudoterminal {
2323
2424 private readonly waitForOpen = new EventWaiter < undefined > ( this . onDidOpen ) ;
2525
26- constructor ( ) { }
26+ constructor ( private readonly cli : CLI ) { }
2727
2828 public async open ( ) : Promise < void > {
2929 this . openEmitter . fire ( undefined ) ;
3030 }
3131
3232 public async close ( ) : Promise < void > { }
3333
34- public setCmdARgs ( cmdArgs : string [ ] ) {
34+ public setCmdArgs ( cmdArgs : string [ ] ) {
3535 this . cmdArgs = cmdArgs ;
3636 }
3737
3838 public async exec ( cwd : string ) : Promise < string > {
3939 await this . waitForOpen . wait ( ) ;
4040
41- let stdout = '' ;
42- let stderr = '' ;
41+ this . write ( this . cmdArgs . join ( ' ' ) + '\n' ) ;
4342
44- this . cmd = spawn ( this . cmdArgs [ 0 ] , this . cmdArgs . slice ( 1 ) , {
45- cwd,
46- env : {
47- ...process . env ,
48- ...getEnvConfig ( ) ,
43+ const { cmd, output } = this . cli . exec ( this . cmdArgs , cwd , {
44+ onStdOut : ( buffer : string ) => {
45+ this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
46+ } ,
47+ onStdErr : ( buffer : string ) => {
48+ this . write ( CLI . removePrefixFromStdOut ( buffer ) ) ;
4949 } ,
5050 } ) ;
51-
52- return new Promise ( res => {
53- // --prefix-output is an internal flag that is added to all commands
54- const argsWithoutPrefixOutput = this . cmdArgs . slice ( 0 , - 1 ) ;
55- this . write ( argsWithoutPrefixOutput . join ( ' ' ) + '\n' ) ;
56-
57- this . cmd ?. stdout . on ( 'data' , data => {
58- const dataString = data . toString ( ) ;
59- stdout += dataString ;
60- this . write ( removePrefixFromStdOut ( dataString ) ) ;
61- } ) ;
62-
63- this . cmd ?. stderr . on ( 'data' , data => {
64- const dataString = data . toString ( ) ;
65- stderr += dataString ;
66- this . write ( removePrefixFromStdOut ( dataString ) ) ;
67- } ) ;
68-
69- this . cmd ?. on ( 'exit' , async _code => {
70- this . cmd = undefined ;
71- const error = stderr || getErrorsFromStdOut ( stdout ) ;
72- if ( error ) {
73- await vscode . window . showErrorMessage ( error ) ;
74- }
75- res ( stdout ) ;
76- } ) ;
77- } ) ;
51+ this . cmd = cmd ;
52+ return await output ;
7853 }
7954
8055 public async handleInput ( data : string ) : Promise < void > {
0 commit comments