@@ -148,6 +148,8 @@ const LF = Buffer.from( [ 0x0A]);
148148
149149const EVENT_STDOUT = 'stdout' ;
150150const EVENT_STDERR = 'stderr' ;
151+ const EVENT_INPUT = 'input' ;
152+ const EVENT_OUTPUT = 'output' ;
151153const EVENT_EXIT = 'exit' ;
152154
153155const TRACE_LEVEL_OFF = 0 ;
@@ -257,6 +259,7 @@ export class Syncline extends EventEmitter {
257259 console . log ( `${ performance . now ( ) } : main: ${ this . #control[ INDEX_LENGTH ] } B written, setting timeout=${ Math . max ( 0 , timeout ) } ms, state=${ STATE_NAMES [ STATE_INPUT_COMPLETE ] } ` ) ;
258260 Atomics . store ( this . #control, INDEX_STATE , STATE_INPUT_COMPLETE ) ;
259261 Atomics . notify ( this . #control, INDEX_STATE , 1 ) ;
262+ this . emit ( EVENT_INPUT , inputLine ) ;
260263
261264 // step 2. receive output
262265 Atomics . wait ( this . #control, INDEX_STATE , STATE_INPUT_COMPLETE ) ;
@@ -277,7 +280,9 @@ export class Syncline extends EventEmitter {
277280 if ( this . #traceLevel >= TRACE_LEVEL_PROTOCOL )
278281 console . log ( `${ performance . now ( ) } : main: state changed to ${ STATE_NAMES [ outputState ] } , reading final ${ length } B and returning` ) ;
279282 buffer . push ( Buffer . from ( this . #shared, OFFSET_DATA , length ) ) ;
280- return Buffer . concat ( buffer ) . toString ( 'utf-8' ) ;
283+ const outputLine = Buffer . concat ( buffer ) . toString ( 'utf-8' ) ;
284+ this . emit ( EVENT_OUTPUT , outputLine ) ;
285+ return outputLine ;
281286 case STATE_ERROR :
282287 if ( this . #traceLevel >= TRACE_LEVEL_PROTOCOL )
283288 console . log ( `${ performance . now ( ) } : main: state changed to ${ STATE_NAMES [ outputState ] } , reading ${ length } B and throwing` ) ;
0 commit comments