2
2
3
3
namespace Clue \React \Stdio ;
4
4
5
- use Clue \React \Stdio \Io \Stdin ;
6
- use Clue \React \Stdio \Io \Stdout ;
7
5
use Evenement \EventEmitter ;
8
6
use React \EventLoop \LoopInterface ;
9
7
use React \Stream \DuplexStreamInterface ;
@@ -23,6 +21,7 @@ class Stdio extends EventEmitter implements DuplexStreamInterface
23
21
private $ closed = false ;
24
22
private $ incompleteLine = '' ;
25
23
private $ originalTtyMode = null ;
24
+ private $ usesExtReadlineHandler = false ;
26
25
27
26
public function __construct (LoopInterface $ loop , ReadableStreamInterface $ input = null , WritableStreamInterface $ output = null , Readline $ readline = null )
28
27
{
@@ -246,8 +245,9 @@ public function handleCloseOutput()
246
245
*/
247
246
private function restoreTtyMode ()
248
247
{
249
- if (function_exists ( ' readline_callback_handler_remove ' ) ) {
248
+ if ($ this -> usesExtReadlineHandler ) {
250
249
// remove dummy readline handler to turn to default input mode
250
+ $ this ->usesExtReadlineHandler = false ;
251
251
readline_callback_handler_remove ();
252
252
} elseif ($ this ->originalTtyMode !== null && $ this ->isTty ()) {
253
253
// Reset stty so it behaves normally again
@@ -279,11 +279,14 @@ private function createStdin(LoopInterface $loop)
279
279
280
280
$ stream = new ReadableResourceStream (STDIN , $ loop );
281
281
282
- if (function_exists ('readline_callback_handler_install ' )) {
282
+ if (PHP_OS === ' Linux ' && function_exists ('readline_callback_handler_install ' )) {
283
283
// Prefer `ext-readline` to install dummy handler to turn on raw input mode.
284
+ // This is known to work on Linux and known to cause issues with CR/LF
285
+ // on Mac, so we only use this on Linux for now, see also issue #66.
284
286
// We will nevery actually feed the readline handler and instead
285
287
// handle all input in our `Readline` implementation.
286
288
readline_callback_handler_install ('' , function () { });
289
+ $ this ->usesExtReadlineHandler = true ;
287
290
return $ stream ;
288
291
}
289
292
0 commit comments