77import * as fs from 'fs' ;
88import * as os from 'os' ;
99import * as path from 'path' ;
10- import { Socket } from 'net' ;
11- import { ArgvOrCommandLine } from './types' ;
12- import { fork } from 'child_process' ;
13- import { ConoutConnection } from './windowsConoutConnection' ;
10+ import { Socket } from 'net' ;
11+ import { ArgvOrCommandLine } from './types' ;
12+ import { fork } from 'child_process' ;
13+ import { ConoutConnection } from './windowsConoutConnection' ;
1414
1515let conptyNative : IConptyNative ;
1616let winptyNative : IWinptyNative ;
@@ -23,6 +23,7 @@ let winptyNative: IWinptyNative;
2323const FLUSH_DATA_INTERVAL = 1000 ;
2424// eslint-disable-next-line @typescript-eslint/naming-convention
2525const __non_webpack_require__ = require ;
26+
2627/**
2728 * This agent sits between the WindowsTerminal class and provides a common interface for both conpty
2829 * and winpty.
@@ -40,11 +41,25 @@ export class WindowsPtyAgent {
4041 private _pty : number ;
4142 private _ptyNative : IConptyNative | IWinptyNative ;
4243
43- public get inSocket ( ) : Socket { return this . _inSocket ; }
44- public get outSocket ( ) : Socket { return this . _outSocket ; }
45- public get fd ( ) : any { return this . _fd ; }
46- public get innerPid ( ) : number { return this . _innerPid ; }
47- public get pty ( ) : number { return this . _pty ; }
44+ public get inSocket ( ) : Socket {
45+ return this . _inSocket ;
46+ }
47+
48+ public get outSocket ( ) : Socket {
49+ return this . _outSocket ;
50+ }
51+
52+ public get fd ( ) : any {
53+ return this . _fd ;
54+ }
55+
56+ public get innerPid ( ) : number {
57+ return this . _innerPid ;
58+ }
59+
60+ public get pty ( ) : number {
61+ return this . _pty ;
62+ }
4863
4964 constructor (
5065 file : string ,
@@ -102,9 +117,9 @@ export class WindowsPtyAgent {
102117 // Open pty session.
103118 let term : IConptyProcess | IWinptyProcess ;
104119 if ( this . _useConpty ) {
105- term = ( this . _ptyNative as IConptyNative ) . startProcess ( file , cols , rows , debug , this . _generatePipeName ( ) , conptyInheritCursor , this . _useConptyDll , exePath ) ;
120+ term = ( this . _ptyNative as IConptyNative ) . startProcess ( file , cols , rows , debug , this . _generatePipeName ( ) , conptyInheritCursor , this . _useConptyDll , exePath ) ;
106121 } else {
107- term = ( this . _ptyNative as IWinptyNative ) . startProcess ( file , commandLine , env , cwd , cols , rows , debug , exePath ) ;
122+ term = ( this . _ptyNative as IWinptyNative ) . startProcess ( file , commandLine , env , cwd , cols , rows , debug , exePath ) ;
108123 this . _pid = ( term as IWinptyProcess ) . pid ;
109124 this . _innerPid = ( term as IWinptyProcess ) . innerPid ;
110125 }
@@ -142,20 +157,20 @@ export class WindowsPtyAgent {
142157 }
143158 }
144159
145- public resize ( cols : number , rows : number , exePath : string = '' ) : void {
160+ public resize ( cols : number , rows : number , exePath : string = '' ) : void {
146161 if ( this . _useConpty ) {
147162 if ( this . _exitCode !== undefined ) {
148163 throw new Error ( 'Cannot resize a pty that has already exited' ) ;
149164 }
150- ( this . _ptyNative as IConptyNative ) . resize ( this . _pty , cols , rows , this . _useConptyDll , exePath ) ;
165+ ( this . _ptyNative as IConptyNative ) . resize ( this . _pty , cols , rows , this . _useConptyDll , exePath ) ;
151166 return ;
152167 }
153168 ( this . _ptyNative as IWinptyNative ) . resize ( this . _pid , cols , rows ) ;
154169 }
155170
156171 public clear ( exePath : string = '' ) : void {
157172 if ( this . _useConpty ) {
158- ( this . _ptyNative as IConptyNative ) . clear ( this . _pty , this . _useConptyDll , exePath ) ;
173+ ( this . _ptyNative as IConptyNative ) . clear ( this . _pty , this . _useConptyDll , exePath ) ;
159174 }
160175 }
161176
@@ -172,7 +187,7 @@ export class WindowsPtyAgent {
172187 // Ignore if process cannot be found (kill ESRCH error)
173188 }
174189 } ) ;
175- ( this . _ptyNative as IConptyNative ) . kill ( this . _pty , this . _useConptyDll , exePath ) ;
190+ ( this . _ptyNative as IConptyNative ) . kill ( this . _pty , this . _useConptyDll , exePath ) ;
176191 } ) ;
177192 } else {
178193 // Because pty.kill closes the handle, it will kill most processes by itself.
@@ -195,6 +210,7 @@ export class WindowsPtyAgent {
195210 }
196211
197212 getConsoleProcessList : any ;
213+
198214 private _getConsoleProcessList ( ) : Promise < number [ ] > {
199215 try {
200216 if ( ! this . getConsoleProcessList ) {
@@ -209,15 +225,15 @@ export class WindowsPtyAgent {
209225 // clearTimeout(timeout);
210226 // resolve(message.consoleProcessList);
211227 // });
212- this . getConsoleProcessList ( this . _innerPid ) . then ( ( consoleProcessList : number [ ] | PromiseLike < number [ ] > | undefined ) => {
228+ this . getConsoleProcessList ( this . _innerPid ) . then ( ( consoleProcessList : number [ ] ) => {
213229 clearTimeout ( timeout ) ;
214- resolve ( consoleProcessList ) ;
230+ resolve ( [ this . innerPid , ... ( consoleProcessList ?? [ ] ) ] ) ;
215231 } ) . catch ( ( error : any ) => {
216- console . error ( 'Error:' , error ) ; // 如果发生错误,会打印出来
217- resolve ( [ this . _innerPid ] ) ;
232+ console . error ( 'Error:' , error ) ; // 如果发生错误
233+ resolve ( [ this . _innerPid ] ) ;
218234 } ) ;
219235 const timeout = setTimeout ( ( ) => {
220- resolve ( [ this . _innerPid ] ) ;
236+ resolve ( [ this . _innerPid ] ) ;
221237 } , 5000 ) ;
222238 } ) ;
223239 }
@@ -290,9 +306,9 @@ export function argsToCommandLine(file: string, args: ArgvOrCommandLine): string
290306 const quote =
291307 arg === '' ||
292308 ( arg . indexOf ( ' ' ) !== - 1 ||
293- arg . indexOf ( '\t' ) !== - 1 ) &&
309+ arg . indexOf ( '\t' ) !== - 1 ) &&
294310 ( ( arg . length > 1 ) &&
295- ( hasLopsidedEnclosingQuote || hasNoEnclosingQuotes ) ) ;
311+ ( hasLopsidedEnclosingQuote || hasNoEnclosingQuotes ) ) ;
296312 if ( quote ) {
297313 result += '\"' ;
298314 }
0 commit comments