File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ public function __construct(LoopInterface $loop)
3232 // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
3333 shell_exec ('stty -icanon -echo ' );
3434 }
35+
36+ // register shutdown function to restore TTY mode in case of unclean shutdown (uncaught exception)
37+ // this will not trigger on SIGKILL etc., but the terminal should take care of this
38+ register_shutdown_function (array ($ this , 'close ' ));
3539 }
3640
3741 public function close ()
@@ -52,6 +56,11 @@ private function restore()
5256 shell_exec (sprintf ('stty %s ' , $ this ->oldMode ));
5357 $ this ->oldMode = null ;
5458 }
59+
60+ // restore blocking mode so following programs behave normally
61+ if (defined ('STDIN ' ) && is_resource (STDIN )) {
62+ stream_set_blocking (STDIN , true );
63+ }
5564 }
5665
5766 /**
You can’t perform that action at this time.
0 commit comments