Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Readline::getPrompt() helper #33

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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