Skip to content

Commit f6c88ab

Browse files
committed
Merge pull request #8 from clue-labs/input
Add accessors for text input buffer.
2 parents 601102d + 3f05faf commit f6c88ab

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Readline.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,35 @@ public function setMove($move)
110110
return $this;
111111
}
112112

113+
/**
114+
* set current text input buffer
115+
*
116+
* this moves the cursor to the end of the current
117+
* input buffer (if any).
118+
*
119+
* @param string $input
120+
* @return self
121+
* @uses self::redraw()
122+
*/
123+
public function setInput($input)
124+
{
125+
$this->linebuffer = $input;
126+
$this->linepos = $this->strlen($this->linebuffer);
127+
$this->redraw();
128+
129+
return $this;
130+
}
131+
132+
/**
133+
* get current text input buffer
134+
*
135+
* @return string
136+
*/
137+
public function getInput()
138+
{
139+
return $this->linebuffer;
140+
}
141+
113142
/**
114143
* set history handler to use (or none)
115144
*

tests/ReadlineTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@ public function testSettersReturnSelf()
1616
$this->assertSame($this->readline, $this->readline->setMove(true));
1717
$this->assertSame($this->readline, $this->readline->setPrompt(''));
1818
}
19+
20+
public function testInputStartsEmpty()
21+
{
22+
$this->assertEquals('', $this->readline->getInput());
23+
}
24+
25+
public function testGetInputAfterSetting()
26+
{
27+
$this->assertSame($this->readline, $this->readline->setInput('hello'));
28+
$this->assertEquals('hello', $this->readline->getInput());
29+
}
1930
}

0 commit comments

Comments
 (0)