diff --git a/src/Stdin.php b/src/Stdin.php index c6e5cf4..c42bdfc 100644 --- a/src/Stdin.php +++ b/src/Stdin.php @@ -32,6 +32,10 @@ public function __construct(LoopInterface $loop) // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); } + + // register shutdown function to restore TTY mode in case of unclean shutdown (uncaught exception) + // this will not trigger on SIGKILL etc., but the terminal should take care of this + register_shutdown_function(array($this, 'close')); } public function close() @@ -52,6 +56,11 @@ private function restore() shell_exec(sprintf('stty %s', $this->oldMode)); $this->oldMode = null; } + + // restore blocking mode so following programs behave normally + if (defined('STDIN') && is_resource(STDIN)) { + stream_set_blocking(STDIN, true); + } } /**