From a9bd82d3dffe6fb1ca423117f190b088022ad1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 16 May 2015 17:32:53 +0200 Subject: [PATCH] Do not redraw() readline if echo replacement results in same line --- src/Readline.php | 6 +++++- tests/ReadlineTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Readline.php b/src/Readline.php index 432f1eb..00a1b1a 100644 --- a/src/Readline.php +++ b/src/Readline.php @@ -164,11 +164,15 @@ public function setInput($input) return $this; } + // remember old input length if echo replacement is used + $oldlen = (is_string($this->echo)) ? $this->strlen($this->linebuffer) : null; + $this->linebuffer = $input; $this->linepos = $this->strlen($this->linebuffer); // only redraw if input should be echo'ed (i.e. is not hidden anyway) - if ($this->echo !== false) { + // and echo replacement is used, make sure the input length changes + if ($this->echo !== false && $this->linepos !== $oldlen) { $this->redraw(); } diff --git a/tests/ReadlineTest.php b/tests/ReadlineTest.php index 717e5fc..4159863 100644 --- a/tests/ReadlineTest.php +++ b/tests/ReadlineTest.php @@ -124,6 +124,16 @@ public function testSettingInputWithEchoAsteriskDoesRedraw() $this->assertSame($this->readline, $this->readline->setInput('test')); } + public function testSettingInputWithSameLengthWithEchoAsteriskDoesNotNeedToRedraw() + { + $this->readline->setInput('test'); + $this->readline->setEcho('*'); + + $this->output->expects($this->never())->method('write'); + + $this->assertSame($this->readline, $this->readline->setInput('demo')); + } + public function testSettingInputWithoutEchoDoesNotNeedToRedraw() { $this->readline->setEcho(false);