Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ public function setMove($move)
return $this;
}

/**
* set current text input buffer
*
* this moves the cursor to the end of the current
* input buffer (if any).
*
* @param string $input
* @return self
* @uses self::redraw()
*/
public function setInput($input)
{
$this->linebuffer = $input;
$this->linepos = $this->strlen($this->linebuffer);
$this->redraw();

return $this;
}

/**
* get current text input buffer
*
* @return string
*/
public function getInput()
{
return $this->linebuffer;
}

/**
* set history handler to use (or none)
*
Expand Down
11 changes: 11 additions & 0 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public function testSettersReturnSelf()
$this->assertSame($this->readline, $this->readline->setMove(true));
$this->assertSame($this->readline, $this->readline->setPrompt(''));
}

public function testInputStartsEmpty()
{
$this->assertEquals('', $this->readline->getInput());
}

public function testGetInputAfterSetting()
{
$this->assertSame($this->readline, $this->readline->setInput('hello'));
$this->assertEquals('hello', $this->readline->getInput());
}
}