mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 19:34:15 +00:00
Added "readline" support using libedit.
This commit is contained in:
parent
c6121e88bf
commit
ff8de264c0
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user