File tree Expand file tree Collapse file tree 3 files changed +44
-7
lines changed Expand file tree Collapse file tree 3 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -537,21 +537,20 @@ public function deleteChar($n)
537
537
538
538
/**
539
539
* process the current line buffer, emit event and redraw empty line
540
+ *
541
+ * @uses self::setInput()
540
542
*/
541
543
protected function processLine ()
542
544
{
545
+ // store and reset/clear/redraw current input
543
546
$ line = $ this ->linebuffer ;
547
+ $ this ->setInput ('' );
544
548
545
- $ this ->emit ('data ' , array ($ line ));
546
-
549
+ // process stored input buffer
547
550
if ($ this ->history !== null ) {
548
551
$ this ->history ->addLine ($ line );
549
552
}
550
-
551
- $ this ->linebuffer = '' ;
552
- $ this ->linepos = 0 ;
553
-
554
- $ this ->redraw ();
553
+ $ this ->emit ('data ' , array ($ line ));
555
554
}
556
555
557
556
protected function strlen ($ str )
Original file line number Diff line number Diff line change @@ -449,6 +449,33 @@ public function testCursorCellObeysCustomEchoAsterisk(Readline $readline)
449
449
$ this ->assertEquals (3 , $ readline ->getCursorCell ());
450
450
}
451
451
452
+ public function testEmitEmptyInputOnEnter ()
453
+ {
454
+ $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('' ));
455
+ $ this ->readline ->onKeyEnter ();
456
+ }
457
+
458
+ public function testEmitInputOnEnterAndClearsInput ()
459
+ {
460
+ $ this ->readline ->setInput ('test ' );
461
+ $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('test ' ));
462
+ $ this ->readline ->onKeyEnter ();
463
+
464
+ $ this ->assertEquals ('' , $ this ->readline ->getInput ());
465
+ }
466
+
467
+ public function testSetInputDuringEmitKeepsInput ()
468
+ {
469
+ $ readline = $ this ->readline ;
470
+
471
+ $ readline ->on ('data ' , function ($ line ) use ($ readline ) {
472
+ $ readline ->setInput ('test ' );
473
+ });
474
+ $ readline ->onKeyEnter ();
475
+
476
+ $ this ->assertEquals ('test ' , $ readline ->getInput ());
477
+ }
478
+
452
479
private function pushInputBytes (Readline $ readline , $ bytes )
453
480
{
454
481
foreach (str_split ($ bytes , 1 ) as $ byte ) {
Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ protected function expectCallableNever()
26
26
return $ mock ;
27
27
}
28
28
29
+ protected function expectCallableOnceWith ($ value )
30
+ {
31
+ $ mock = $ this ->createCallableMock ();
32
+ $ mock
33
+ ->expects ($ this ->once ())
34
+ ->method ('__invoke ' )
35
+ ->with ($ this ->equalTo ($ value ));
36
+
37
+ return $ mock ;
38
+ }
39
+
29
40
protected function expectCallableOnceParameter ($ type )
30
41
{
31
42
$ mock = $ this ->createCallableMock ();
You can’t perform that action at this time.
0 commit comments