From 80dca993d7ebb395c85aeaa67bf8322f236a05a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 7 Jun 2016 22:07:52 +0200 Subject: [PATCH] Add Readline::getPrompt() helper --- README.md | 7 +++++++ src/Readline.php | 11 +++++++++++ tests/ReadlineTest.php | 7 +++++++ 3 files changed, 25 insertions(+) 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');