@@ -24,7 +24,11 @@ class OutputInterceptor extends Writable {
2424 this . paused = false ;
2525 }
2626
27- _write ( chunk : Buffer | string , encoding : BufferEncoding , callback : ( error ?: Error | null ) => void ) : void {
27+ _write (
28+ chunk : Buffer | string ,
29+ encoding : BufferEncoding ,
30+ callback : ( error ?: Error | null ) => void ,
31+ ) : void {
2832 if ( ! this . paused ) {
2933 this . originalStdout . write ( chunk , encoding ) ;
3034 }
@@ -36,83 +40,92 @@ class OutputInterceptor extends Writable {
3640export const initInteractiveInput = ( ) => {
3741 // Save original stdout
3842 const originalStdout = process . stdout ;
39-
43+
4044 // Create interceptor
4145 const interceptor = new OutputInterceptor ( originalStdout ) ;
42-
46+
4347 // Replace stdout with our interceptor
4448 // @ts -expect-error - This is a hack to replace stdout
4549 process . stdout = interceptor ;
46-
50+
4751 // Create readline interface for listening to key presses
4852 const rl = readline . createInterface ( {
4953 input : process . stdin ,
5054 output : interceptor ,
5155 terminal : true ,
5256 } ) ;
53-
57+
5458 // Close the interface to avoid keeping the process alive
5559 rl . close ( ) ;
56-
60+
5761 // Listen for keypress events
5862 readline . emitKeypressEvents ( process . stdin ) ;
5963 if ( process . stdin . isTTY ) {
6064 process . stdin . setRawMode ( true ) ;
6165 }
62-
66+
6367 process . stdin . on ( 'keypress' , async ( str , key ) => {
6468 // Check for Ctrl+C to exit
6569 if ( key . ctrl && key . name === 'c' ) {
6670 process . exit ( 0 ) ;
6771 }
68-
72+
6973 // Check for Ctrl+M to enter message mode
7074 if ( key . ctrl && key . name === 'm' ) {
7175 // Pause output
7276 interceptor . pause ( ) ;
73-
77+
7478 // Create a readline interface for input
7579 const inputRl = createInterface ( {
7680 input : process . stdin ,
7781 output : originalStdout ,
7882 } ) ;
79-
83+
8084 try {
8185 // Reset cursor position and clear line
8286 originalStdout . write ( '\r\n' ) ;
83- originalStdout . write ( chalk . green ( 'Enter correction or additional context (Ctrl+C to cancel):\n' ) + '> ' ) ;
84-
87+ originalStdout . write (
88+ chalk . green (
89+ 'Enter correction or additional context (Ctrl+C to cancel):\n' ,
90+ ) + '> ' ,
91+ ) ;
92+
8593 // Get user input
8694 const userInput = await inputRl . question ( '' ) ;
87-
95+
8896 // Add message to queue if not empty
8997 if ( userInput . trim ( ) ) {
9098 userMessages . push ( userInput ) ;
91- originalStdout . write ( chalk . green ( '\nMessage sent to agent. Resuming output...\n\n' ) ) ;
99+ originalStdout . write (
100+ chalk . green ( '\nMessage sent to agent. Resuming output...\n\n' ) ,
101+ ) ;
92102 } else {
93- originalStdout . write ( chalk . yellow ( '\nEmpty message not sent. Resuming output...\n\n' ) ) ;
103+ originalStdout . write (
104+ chalk . yellow ( '\nEmpty message not sent. Resuming output...\n\n' ) ,
105+ ) ;
94106 }
95107 } catch ( error ) {
96- originalStdout . write ( chalk . red ( `\nError sending message: ${ error } \n\n` ) ) ;
108+ originalStdout . write (
109+ chalk . red ( `\nError sending message: ${ error } \n\n` ) ,
110+ ) ;
97111 } finally {
98112 // Close input readline interface
99113 inputRl . close ( ) ;
100-
114+
101115 // Resume output
102116 interceptor . resume ( ) ;
103117 }
104118 }
105119 } ) ;
106-
120+
107121 // Return a cleanup function
108122 return ( ) => {
109123 // Restore original stdout
110- // @ts -expect-error - This is a hack to restore stdout
111124 process . stdout = originalStdout ;
112-
125+
113126 // Disable raw mode
114127 if ( process . stdin . isTTY ) {
115128 process . stdin . setRawMode ( false ) ;
116129 }
117130 } ;
118- } ;
131+ } ;
0 commit comments