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