Skip to content

Commit

Permalink
Add Readline::getPrompt() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 10, 2016
1 parent eeb7d4f commit 80dca99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down
11 changes: 11 additions & 0 deletions src/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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');
Expand Down

0 comments on commit 80dca99

Please sign in to comment.