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)
32
32
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
33
33
shell_exec ('stty -icanon -echo ' );
34
34
}
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 ' ));
35
39
}
36
40
37
41
public function close ()
@@ -52,6 +56,11 @@ private function restore()
52
56
shell_exec (sprintf ('stty %s ' , $ this ->oldMode ));
53
57
$ this ->oldMode = null ;
54
58
}
59
+
60
+ // restore blocking mode so following programs behave normally
61
+ if (defined ('STDIN ' ) && is_resource (STDIN )) {
62
+ stream_set_blocking (STDIN , true );
63
+ }
55
64
}
56
65
57
66
/**
You can’t perform that action at this time.
0 commit comments