Skip to content

Commit 3662847

Browse files
authored
Merge pull request #33 from clue-labs/prompt
Add Readline::getPrompt() helper
2 parents 9379345 + 80dca99 commit 3662847

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ You can restore this behavior by passing an empty prompt:
117117
$readline->setPrompt('');
118118
```
119119

120+
The `getPrompt()` method can be used to get the current input prompt.
121+
It will return an empty string unless you've set anything else:
122+
123+
```php
124+
assert($readline->getPrompt() === '');
125+
```
126+
120127
#### Echo
121128

122129
The *echo mode* controls how the actual *user input buffer* will be presented in the *user input line*.

src/Readline.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ public function setPrompt($prompt)
122122
return $this->redraw();
123123
}
124124

125+
/**
126+
* returns the prompt to prepend to input line
127+
*
128+
* @return string
129+
* @see self::setPrompt()
130+
*/
131+
public function getPrompt()
132+
{
133+
return $this->prompt;
134+
}
135+
125136
/**
126137
* sets whether/how to echo text input
127138
*

tests/ReadlineTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function testSettersReturnSelf()
2626

2727
public function testInputStartsEmpty()
2828
{
29+
$this->assertEquals('', $this->readline->getPrompt());
2930
$this->assertEquals('', $this->readline->getInput());
3031
$this->assertEquals(0, $this->readline->getCursorPosition());
3132
$this->assertEquals(0, $this->readline->getCursorCell());
@@ -39,6 +40,12 @@ public function testGetInputAfterSetting()
3940
$this->assertEquals(5, $this->readline->getCursorCell());
4041
}
4142

43+
public function testPromptAfterSetting()
44+
{
45+
$this->assertSame($this->readline, $this->readline->setPrompt('> '));
46+
$this->assertEquals('> ' , $this->readline->getPrompt());
47+
}
48+
4249
public function testSettingInputMovesCursorToEnd()
4350
{
4451
$this->readline->setInput('hello');

0 commit comments

Comments
 (0)