Added "readline" support using libedit.

This commit is contained in:
Greyson Fischer 2013-05-20 02:58:32 -04:00
parent c6121e88bf
commit ff8de264c0

View File

@ -297,6 +297,7 @@ class ConsoleLoop extends Thread{
public $stop;
public $base;
public $ev;
public $fp;
public function __construct(){
$this->line = false;
$this->stop = false;
@ -307,21 +308,33 @@ class ConsoleLoop extends Thread{
$this->stop = true;
}
public function readLine($fp, $events = null){
$line = trim(fgets($fp));
private function readLine(){
if( $this->fp ){
$line = trim( fgets( $this->fp ) );
} else {
$line = trim( readline( "" ) );
if( $line != "" ){
$this->line = $line;
readline_add_history( $line );
}
}
return $line;
}
public function run(){
$fp = fopen("php://stdin", "r");
while($this->stop === false and ($line = fgets($fp)) !== false){
$this->line = $line;
if( ! extension_loaded( 'readline' ) ){
$this->fp = fopen( "php://stdin", "r" );
}
while( $this->stop === false ) {
$this->line = $this->readLine();
$this->wait();
$this->line = false;
}
if( ! $this->haveReadline ) {
@fclose($fp);
}
exit(0);
}
}