@@ -115,6 +115,10 @@ export class BJShell {
115
115
async changelineModeToKeypress (
116
116
keypressListener : ( key : string , data : any ) => Promise < void >
117
117
) {
118
+ if ( this ?. keyeventListener ) {
119
+ console . log ( chalk . red ( "Already in keypress mode! override previous listener." ) ) ;
120
+ await this . revertlineModeFromKeypress ( ) ;
121
+ }
118
122
this . r . removeListener ( "line" , this . lineListener ) ;
119
123
readline . emitKeypressEvents ( process . stdin ) ;
120
124
process . stdin . setRawMode ( true ) ;
@@ -132,6 +136,8 @@ export class BJShell {
132
136
}
133
137
this . r . write ( null , { ctrl : true , name : "u" } ) ;
134
138
await this . setPrompt ( ) ;
139
+ // re-register line listener (assure 1 listener)
140
+ this . r . removeListener ( "line" , this . lineListener ) ;
135
141
this . r . on ( "line" , this . lineListener ) ;
136
142
}
137
143
@@ -140,6 +146,9 @@ export class BJShell {
140
146
this . r . on ( "close" , function ( ) {
141
147
process . exit ( ) ;
142
148
} ) ;
149
+ this . r . setMaxListeners ( 1 ) ;
150
+ // onkeypress listener is already registered
151
+ process . stdin . setMaxListeners ( 2 ) ;
143
152
144
153
// Handle Ctrl+C (SIGINT) to send it to the child process
145
154
this . r . on ( "SIGINT" , async ( ) => {
0 commit comments