diff --git a/src/Readline.php b/src/Readline.php index 0afc161..dae85b8 100644 --- a/src/Readline.php +++ b/src/Readline.php @@ -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) * diff --git a/tests/ReadlineTest.php b/tests/ReadlineTest.php index 7eb07ea..20e507e 100644 --- a/tests/ReadlineTest.php +++ b/tests/ReadlineTest.php @@ -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()); + } }