Skip to content

Commit 6ddec4c

Browse files
committed
Merge pull request #14 from clue-labs/redraw-echo
Do not redraw() readline if echo replacement results in same line
2 parents 60dfbf0 + a9bd82d commit 6ddec4c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Readline.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,15 @@ public function setInput($input)
203203
return $this;
204204
}
205205

206+
// remember old input length if echo replacement is used
207+
$oldlen = (is_string($this->echo)) ? $this->strlen($this->linebuffer) : null;
208+
206209
$this->linebuffer = $input;
207210
$this->linepos = $this->strlen($this->linebuffer);
208211

209212
// only redraw if input should be echo'ed (i.e. is not hidden anyway)
210-
if ($this->echo !== false) {
213+
// and echo replacement is used, make sure the input length changes
214+
if ($this->echo !== false && $this->linepos !== $oldlen) {
211215
$this->redraw();
212216
}
213217

tests/ReadlineTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ public function testSettingInputWithEchoAsteriskDoesRedraw()
124124
$this->assertSame($this->readline, $this->readline->setInput('test'));
125125
}
126126

127+
public function testSettingInputWithSameLengthWithEchoAsteriskDoesNotNeedToRedraw()
128+
{
129+
$this->readline->setInput('test');
130+
$this->readline->setEcho('*');
131+
132+
$this->output->expects($this->never())->method('write');
133+
134+
$this->assertSame($this->readline, $this->readline->setInput('demo'));
135+
}
136+
127137
public function testSettingInputWithoutEchoDoesNotNeedToRedraw()
128138
{
129139
$this->readline->setEcho(false);

0 commit comments

Comments
 (0)