From 0d6f7e5fc897024f72fcd853aefae3b6be11e751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 29 May 2015 17:23:05 +0200 Subject: [PATCH 1/2] Restore TTY mode on unclean shutdown (uncaught exception) --- src/Stdin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Stdin.php b/src/Stdin.php index c6e5cf4..c775426 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() From 4c8437438ed2dd366432bf3626da462d0bda3f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 1 Nov 2017 15:37:09 +0100 Subject: [PATCH 2/2] Restore STDIN to default blocking mode before closing --- src/Stdin.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Stdin.php b/src/Stdin.php index c775426..c42bdfc 100644 --- a/src/Stdin.php +++ b/src/Stdin.php @@ -56,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); + } } /**