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,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));
|
||||
if($line != ""){
|
||||
$this->line = $line;
|
||||
private function readLine(){
|
||||
if( $this->fp ){
|
||||
$line = trim( fgets( $this->fp ) );
|
||||
} else {
|
||||
$line = trim( readline( "" ) );
|
||||
if( $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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user