mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
CommandReader: removed readline support
readline has been borked for a long time and it's not thread safe.
This commit is contained in:
@ -25,23 +25,18 @@ namespace pocketmine\command;
|
|||||||
|
|
||||||
use pocketmine\snooze\SleeperNotifier;
|
use pocketmine\snooze\SleeperNotifier;
|
||||||
use pocketmine\Thread;
|
use pocketmine\Thread;
|
||||||
use pocketmine\utils\Utils;
|
|
||||||
use function extension_loaded;
|
|
||||||
use function fclose;
|
use function fclose;
|
||||||
use function fgets;
|
use function fgets;
|
||||||
use function fopen;
|
use function fopen;
|
||||||
use function fstat;
|
use function fstat;
|
||||||
use function getopt;
|
|
||||||
use function is_resource;
|
use function is_resource;
|
||||||
use function microtime;
|
use function microtime;
|
||||||
use function preg_replace;
|
use function preg_replace;
|
||||||
use function readline;
|
use function readline;
|
||||||
use function readline_add_history;
|
|
||||||
use function stream_isatty;
|
use function stream_isatty;
|
||||||
use function stream_select;
|
use function stream_select;
|
||||||
use function trim;
|
use function trim;
|
||||||
use function usleep;
|
use function usleep;
|
||||||
use const STDIN;
|
|
||||||
|
|
||||||
class CommandReader extends Thread{
|
class CommandReader extends Thread{
|
||||||
|
|
||||||
@ -65,12 +60,6 @@ class CommandReader extends Thread{
|
|||||||
public function __construct(?SleeperNotifier $notifier = null){
|
public function __construct(?SleeperNotifier $notifier = null){
|
||||||
$this->buffer = new \Threaded;
|
$this->buffer = new \Threaded;
|
||||||
$this->notifier = $notifier;
|
$this->notifier = $notifier;
|
||||||
|
|
||||||
$opts = getopt("", ["disable-readline", "enable-readline"]);
|
|
||||||
|
|
||||||
if(extension_loaded("readline") and (Utils::getOS() === Utils::OS_WINDOWS ? isset($opts["enable-readline"]) : !isset($opts["disable-readline"])) and !$this->isPipe(STDIN)){
|
|
||||||
$this->type = self::TYPE_READLINE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,13 +117,7 @@ class CommandReader extends Thread{
|
|||||||
*/
|
*/
|
||||||
private function readLine() : bool{
|
private function readLine() : bool{
|
||||||
$line = "";
|
$line = "";
|
||||||
if($this->type === self::TYPE_READLINE){
|
|
||||||
if(($raw = readline("> ")) !== false and ($line = trim($raw)) !== ""){
|
|
||||||
readline_add_history($line);
|
|
||||||
}else{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(!is_resource(self::$stdin)){
|
if(!is_resource(self::$stdin)){
|
||||||
$this->initStdin();
|
$this->initStdin();
|
||||||
}
|
}
|
||||||
@ -163,7 +146,6 @@ class CommandReader extends Thread{
|
|||||||
$line = trim($raw);
|
$line = trim($raw);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if($line !== ""){
|
if($line !== ""){
|
||||||
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
|
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
|
||||||
@ -193,19 +175,13 @@ class CommandReader extends Thread{
|
|||||||
*/
|
*/
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->registerClassLoader();
|
$this->registerClassLoader();
|
||||||
|
|
||||||
if($this->type !== self::TYPE_READLINE){
|
|
||||||
$this->initStdin();
|
$this->initStdin();
|
||||||
}
|
|
||||||
|
|
||||||
while(!$this->shutdown and $this->readLine());
|
while(!$this->shutdown and $this->readLine());
|
||||||
|
|
||||||
if($this->type !== self::TYPE_READLINE){
|
|
||||||
fclose(self::$stdin);
|
fclose(self::$stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getThreadName() : string{
|
public function getThreadName() : string{
|
||||||
return "Console";
|
return "Console";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user