Skip to content
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
16 changes: 16 additions & 0 deletions src/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ public function __construct($output)
* Will redraw the current input prompt with the current input buffer.
*
* @param string $prompt
* @return self
* @uses self::redraw()
*/
public function setPrompt($prompt)
{
$this->prompt = $prompt;
$this->redraw();

return $this;
}

/**
Expand All @@ -76,12 +79,15 @@ public function setPrompt($prompt)
* the new setting.
*
* @param boolean $echo
* @return self
* @uses self::redraw()
*/
public function setEcho($echo)
{
$this->echo = !!$echo;
$this->redraw();

return $this;
}

/**
Expand All @@ -91,13 +97,17 @@ public function setEcho($echo)
* input buffer (if any).
*
* @param boolean $move
* @return self
* @uses self::redraw()
*/
public function setMove($move)
{
$this->move = !!$move;

$this->linepos = $this->strlen($this->linebuffer);
$this->redraw();

return $this;
}

/**
Expand All @@ -107,10 +117,13 @@ public function setMove($move)
* arrow keys.
*
* @param HistoryInterface|null $history
* @return self
*/
public function setHistory(HistoryInterface $history = null)
{
$this->history = $history;

return $this;
}

/**
Expand All @@ -120,10 +133,13 @@ public function setHistory(HistoryInterface $history = null)
* key.
*
* @param AutocompleteInterface|null $autocomplete
* @return self
*/
public function setAutocomplete(AutocompleteInterface $autocomplete = null)
{
$this->autocomplete = $autocomplete;

return $this;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Clue\React\Stdio\Readline;

class ReadlineTest extends TestCase
{
public function setUp()
{
$output = $this->getMockBuilder('Clue\React\Stdio\Stdout')->disableOriginalConstructor()->getMock();
$this->readline = new Readline($output);
}

public function testSettersReturnSelf()
{
$this->assertSame($this->readline, $this->readline->setEcho(true));
$this->assertSame($this->readline, $this->readline->setMove(true));
$this->assertSame($this->readline, $this->readline->setPrompt(''));
}
}