diff --git a/README.md b/README.md index e6c99d2..8956fd4 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,13 @@ You can restore this behavior by passing an empty prompt: $readline->setPrompt(''); ``` +The `getPrompt()` method can be used to get the current input prompt. +It will return an empty string unless you've set anything else: + +```php +assert($readline->getPrompt() === ''); +``` + #### Echo The *echo mode* controls how the actual *user input buffer* will be presented in the *user input line*. diff --git a/src/Readline.php b/src/Readline.php index bac4209..c5318cb 100644 --- a/src/Readline.php +++ b/src/Readline.php @@ -122,6 +122,17 @@ public function setPrompt($prompt) return $this->redraw(); } + /** + * returns the prompt to prepend to input line + * + * @return string + * @see self::setPrompt() + */ + public function getPrompt() + { + return $this->prompt; + } + /** * sets whether/how to echo text input * diff --git a/tests/ReadlineTest.php b/tests/ReadlineTest.php index d7eea80..4671243 100644 --- a/tests/ReadlineTest.php +++ b/tests/ReadlineTest.php @@ -26,6 +26,7 @@ public function testSettersReturnSelf() public function testInputStartsEmpty() { + $this->assertEquals('', $this->readline->getPrompt()); $this->assertEquals('', $this->readline->getInput()); $this->assertEquals(0, $this->readline->getCursorPosition()); $this->assertEquals(0, $this->readline->getCursorCell()); @@ -39,6 +40,12 @@ public function testGetInputAfterSetting() $this->assertEquals(5, $this->readline->getCursorCell()); } + public function testPromptAfterSetting() + { + $this->assertSame($this->readline, $this->readline->setPrompt('> ')); + $this->assertEquals('> ' , $this->readline->getPrompt()); + } + public function testSettingInputMovesCursorToEnd() { $this->readline->setInput('hello');