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