Skip to content

Commit a62268d

Browse files
authored
Merge pull request #73 from clue-labs/readline-mac
Don't use ext-readline handler on Mac to fix CR/LF issues on Mac only
2 parents 8777add + d6ae898 commit a62268d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,11 @@ If this extension is missing, then this library will use a slighty slower Regex
607607
work-around that should otherwise work equally well.
608608
Installing `ext-mbstring` is highly recommended.
609609

610-
Internally, it will use the `ext-readline` to enable raw terminal input mode.
611-
If this extension is missing, then this library will manually set the required
612-
TTY settings on start and will try to restore previous settings on exit.
613-
Input line editing is handled entirely within this library and does not rely on
614-
`ext-readline`.
610+
Internally, it will use the `ext-readline` to enable raw terminal input mode (on
611+
Linux only as it is known to cause issues on Macs). Otherwise, this library will
612+
manually set the required TTY settings on start and will try to restore previous
613+
settings on exit. Input line editing is handled entirely within this library and
614+
does not rely on `ext-readline`.
615615
Installing `ext-readline` is entirely optional.
616616

617617
Note that *Microsoft Windows is not supported*.

src/Stdio.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Clue\React\Stdio;
44

5-
use Clue\React\Stdio\Io\Stdin;
6-
use Clue\React\Stdio\Io\Stdout;
75
use Evenement\EventEmitter;
86
use React\EventLoop\LoopInterface;
97
use React\Stream\DuplexStreamInterface;
@@ -23,6 +21,7 @@ class Stdio extends EventEmitter implements DuplexStreamInterface
2321
private $closed = false;
2422
private $incompleteLine = '';
2523
private $originalTtyMode = null;
24+
private $usesExtReadlineHandler = false;
2625

2726
public function __construct(LoopInterface $loop, ReadableStreamInterface $input = null, WritableStreamInterface $output = null, Readline $readline = null)
2827
{
@@ -246,8 +245,9 @@ public function handleCloseOutput()
246245
*/
247246
private function restoreTtyMode()
248247
{
249-
if (function_exists('readline_callback_handler_remove')) {
248+
if ($this->usesExtReadlineHandler) {
250249
// remove dummy readline handler to turn to default input mode
250+
$this->usesExtReadlineHandler = false;
251251
readline_callback_handler_remove();
252252
} elseif ($this->originalTtyMode !== null && $this->isTty()) {
253253
// Reset stty so it behaves normally again
@@ -279,11 +279,14 @@ private function createStdin(LoopInterface $loop)
279279

280280
$stream = new ReadableResourceStream(STDIN, $loop);
281281

282-
if (function_exists('readline_callback_handler_install')) {
282+
if (PHP_OS === 'Linux' && function_exists('readline_callback_handler_install')) {
283283
// 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.
284286
// We will nevery actually feed the readline handler and instead
285287
// handle all input in our `Readline` implementation.
286288
readline_callback_handler_install('', function () { });
289+
$this->usesExtReadlineHandler = true;
287290
return $stream;
288291
}
289292

0 commit comments

Comments
 (0)