@@ -33,14 +33,12 @@ class Readline extends EventEmitter
3333 private $ history = null ;
3434 private $ encoding = 'utf-8 ' ;
3535
36+ private $ input ;
3637 private $ output ;
3738 private $ sequencer ;
3839
3940 public function __construct (ReadableStreamInterface $ input , WritableStreamInterface $ output )
4041 {
41- // input data emits a single char into readline
42- $ input ->on ('data ' , array ($ this , 'onChar ' ));
43-
4442 $ this ->output = $ output ;
4543
4644 $ this ->sequencer = new Sequencer ();
@@ -89,6 +87,9 @@ public function __construct(ReadableStreamInterface $input, WritableStreamInterf
8987 $ this ->sequencer ->addFallback (self ::ESC_SEQUENCE , function ($ bytes ) {
9088 echo 'unknown sequence: ' . ord ($ bytes ) . PHP_EOL ;
9189 });
90+
91+ // input data emits a single char into readline
92+ $ input ->on ('data ' , array ($ this ->sequencer , 'push ' ));
9293 }
9394
9495 /**
@@ -374,7 +375,7 @@ public function redraw()
374375 // write output, then move back $reverse chars (by sending backspace)
375376 $ output .= $ buffer . str_repeat ("\x08" , $ this ->strwidth ($ buffer ) - $ this ->getCursorCell ());
376377 }
377- $ this ->write ($ output );
378+ $ this ->output -> write ($ output );
378379
379380 return $ this ;
380381 }
@@ -394,18 +395,12 @@ public function redraw()
394395 public function clear ()
395396 {
396397 if ($ this ->prompt !== '' || ($ this ->echo !== false && $ this ->linebuffer !== '' )) {
397- $ this ->write ("\r\033[K " );
398+ $ this ->output -> write ("\r\033[K " );
398399 }
399400
400401 return $ this ;
401402 }
402403
403- /** @internal */
404- public function onChar ($ char )
405- {
406- $ this ->sequencer ->push ($ char );
407- }
408-
409404 /** @internal */
410405 public function onKeyBackspace ()
411406 {
@@ -454,7 +449,7 @@ public function onKeyTab()
454449 public function onKeyEnter ()
455450 {
456451 if ($ this ->echo !== false ) {
457- $ this ->write ("\n" );
452+ $ this ->output -> write ("\n" );
458453 }
459454 $ this ->processLine ();
460455 }
@@ -575,9 +570,4 @@ private function strwidth($str)
575570 {
576571 return mb_strwidth ($ str , $ this ->encoding );
577572 }
578-
579- protected function write ($ data )
580- {
581- $ this ->output ->write ($ data );
582- }
583573}
0 commit comments