@@ -12,6 +12,10 @@ class Stdin extends Stream
12
12
{
13
13
private $ oldMode = null ;
14
14
15
+ /**
16
+ * @param LoopInterface $loop
17
+ * @codeCoverageIgnore this is covered by functional tests with/without ext-readline
18
+ */
15
19
public function __construct (LoopInterface $ loop )
16
20
{
17
21
// STDIN not defined ("php -a") or already closed (`fclose(STDIN)`)
@@ -28,6 +32,14 @@ public function __construct(LoopInterface $loop)
28
32
return $ this ->close ();
29
33
}
30
34
35
+ if (function_exists ('readline_callback_handler_install ' )) {
36
+ // Prefer `ext-readline` to install dummy handler to turn on raw input mode.
37
+ // We will nevery actually feed the readline handler and instead
38
+ // handle all input in our `Readline` implementation.
39
+ readline_callback_handler_install ('' , function () { });
40
+ return ;
41
+ }
42
+
31
43
if ($ this ->isTty ()) {
32
44
$ this ->oldMode = shell_exec ('stty -g ' );
33
45
@@ -51,9 +63,15 @@ public function __destruct()
51
63
$ this ->restore ();
52
64
}
53
65
66
+ /**
67
+ * @codeCoverageIgnore this is covered by functional tests with/without ext-readline
68
+ */
54
69
private function restore ()
55
70
{
56
- if ($ this ->oldMode !== null && $ this ->isTty ()) {
71
+ if (function_exists ('readline_callback_handler_remove ' )) {
72
+ // remove dummy readline handler to turn to default input mode
73
+ readline_callback_handler_remove ();
74
+ } elseif ($ this ->oldMode !== null && $ this ->isTty ()) {
57
75
// Reset stty so it behaves normally again
58
76
shell_exec (sprintf ('stty %s ' , $ this ->oldMode ));
59
77
$ this ->oldMode = null ;
0 commit comments