CommandReader: removed readline support

readline has been borked for a long time and it's not thread safe.
This commit is contained in:
Dylan K. Taylor
2021-01-25 17:53:25 +00:00
parent 31b6df4376
commit 62deafda48

View File

@ -25,23 +25,18 @@ namespace pocketmine\command;
use pocketmine\snooze\SleeperNotifier;
use pocketmine\Thread;
use pocketmine\utils\Utils;
use function extension_loaded;
use function fclose;
use function fgets;
use function fopen;
use function fstat;
use function getopt;
use function is_resource;
use function microtime;
use function preg_replace;
use function readline;
use function readline_add_history;
use function stream_isatty;
use function stream_select;
use function trim;
use function usleep;
use const STDIN;
class CommandReader extends Thread{
@ -65,12 +60,6 @@ class CommandReader extends Thread{
public function __construct(?SleeperNotifier $notifier = null){
$this->buffer = new \Threaded;
$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{
$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)){
$this->initStdin();
}
@ -163,7 +146,6 @@ class CommandReader extends Thread{
$line = trim($raw);
break;
}
}
if($line !== ""){
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
@ -193,19 +175,13 @@ class CommandReader extends Thread{
*/
public function run(){
$this->registerClassLoader();
if($this->type !== self::TYPE_READLINE){
$this->initStdin();
}
while(!$this->shutdown and $this->readLine());
if($this->type !== self::TYPE_READLINE){
fclose(self::$stdin);
}
}
public function getThreadName() : string{
return "Console";
}