Skip to content

Commit

Permalink
Merge pull request #14 from clue-labs/redraw-echo
Browse files Browse the repository at this point in the history
Do not redraw() readline if echo replacement results in same line
  • Loading branch information
clue committed May 17, 2015
2 parents 60dfbf0 + a9bd82d commit 6ddec4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,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();
}

Expand Down
10 changes: 10 additions & 0 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6ddec4c

Please sign in to comment.