File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -405,11 +405,33 @@ async function cleanup(): Promise<void> {
405
405
}
406
406
}
407
407
408
+
409
+ process . stdin . setRawMode ( false ) ;
408
410
readline . close ( ) ;
409
411
console . log ( '\nGoodbye!' ) ;
410
412
process . exit ( 0 ) ;
411
413
}
412
414
415
+ // Set up raw mode for keyboard input to capture Escape key
416
+ process . stdin . setRawMode ( true ) ;
417
+ process . stdin . on ( 'data' , async ( data ) => {
418
+ // Check for Escape key (27)
419
+ if ( data . length === 1 && data [ 0 ] === 27 ) {
420
+ console . log ( '\nESC key pressed. Disconnecting from server...' ) ;
421
+
422
+ // Abort current operation and disconnect from server
423
+ if ( client && transport ) {
424
+ await disconnect ( ) ;
425
+ console . log ( 'Disconnected. Press Enter to continue.' ) ;
426
+ } else {
427
+ console . log ( 'Not connected to server.' ) ;
428
+ }
429
+
430
+ // Re-display the prompt
431
+ process . stdout . write ( '> ' ) ;
432
+ }
433
+ } ) ;
434
+
413
435
// Handle Ctrl+C
414
436
process . on ( 'SIGINT' , async ( ) => {
415
437
console . log ( '\nReceived SIGINT. Cleaning up...' ) ;
You can’t perform that action at this time.
0 commit comments