private function readLine() { if (!$this->readline) { $line = trim(fgets($this->stdin)); if ($line !== "") { $this->buffer[] = $line; } } else { readline_callback_read_char(); } }
public function resume() { if ($this->listening) { return; } if (!function_exists('readline_callback_handler_install')) { throw new BadMethodCallException('Method "readline_callback_handler_install" not available, update PHP and/or enable ext-readline'); } $this->listening = true; readline_callback_handler_install($this->prompt, array($this, 'handleLine')); $this->loop->addReadStream(STDIN, function () { readline_callback_read_char(); }); }
function run() { $this->install_handler(); readline_completion_function(array($this, 'callback_complete')); while ($this->prompting) { $w = NULL; $e = NULL; $r = array(STDIN); $n = stream_select($r, $w, $e, null); if ($n && in_array(STDIN, $r)) { // read a character, will call the callback when a newline is entered readline_callback_read_char(); } } echo "Exit.\n"; }
function readline_predefined($prompt, $predefined_text = "") { global $readline, $prompt_finished; readline_callback_handler_install($prompt, 'readline_callback'); for ($i = 0; $i < strlen($predefined_text); $i++) { readline_info('pending_input', substr($predefined_text, $i, 1)); readline_callback_read_char(); } $readline = FALSE; $prompt_finished = FALSE; while (!$prompt_finished) { readline_callback_read_char(); } return $readline; }
private function myReadline() { $this->lastCommand = NULL; readline_callback_handler_install($this->prompt, array($this, 'readlineCallback')); while ($this->lastCommand === NULL) { readline_callback_read_char(); } return $this->lastCommand; }
private function realReadline() { $this->inReadline = true; while ($this->inReadline) { $w = NULL; $e = NULL; $r = array(STDIN); $n = @stream_select($r, $w, $e, NULL); // @ to silence warning on ctl-c // detect ctl-c or other signal (causes stream_select to exit with FALSE) if ($n === false) { readline_callback_handler_remove(); print "\n"; readline_callback_handler_install($this->inputPrompt, array($this, 'doCommand')); } if (in_array(STDIN, $r)) { readline_callback_read_char(); } } }
function repl() { $title = "Quack interactive mode"; if (isPOSIX()) { fwrite(STDOUT, "]2;{$title}"); } else { `title {$title}`; } echo "Type ^C or :quit to leave", PHP_EOL; install_stream_handler(); while (true) { if (isPOSIX()) { $write = null; $except = null; $stream = @stream_select($read = [STDIN], $write, $except, null); if ($stream && in_array(STDIN, $read)) { readline_callback_read_char(); } } else { $line = stream_get_line(STDIN, 1024, PHP_EOL); readline_callback($line); } } }
public function readline() { if (!$this->hasReadline) { // read a character, will call the callback when a newline is entered $line = fgets(STDIN, 1024); $line = !$line && strlen($line) == 0 ? false : rtrim($line); $this->runCommand($line); } else { readline_callback_read_char(); } // @codeCoverageIgnoreEnd }
/** * 可以处理IO的readline */ public function readio_readline($prompt) { readline_callback_handler_install($prompt, array($this, 'readio_handler')); $this->_inputLine = ''; $this->_inputFinished = false; while (!$this->_inputFinished) { $w = NULL; $e = NULL; $r = array(STDIN); $n = @stream_select($r, $w, $e, null); // var_dump($n, $r, $w, $e); if ($n === false) { // echo "io incrupt\n"; // exit; } else { if ($n && in_array(STDIN, $r)) { // read a character, will call the callback when a newline is entered readline_callback_read_char(); $rli = readline_info(); // print_r($rli); } } } return $this->_inputLine; }
} $console->showPrompt(); /* wait for something to happen */ $w = $e = NULL; if (($r = stream_select($read, $w, $e, 60)) === false) { die("select"); } if ($r == 0) { /* TODO: check if there's still a connection */ continue; } foreach ($read as $fd) { $fd_name = array_search($fd, $fds); if ($fd_name == 'stdin') { /* let readline handle use input */ readline_callback_read_char(); } elseif ($fd_name == 'sck') { if (feof($fd)) { $ret = FALSE; } else { $ret = $console->debugger->getData(); } if ($ret === FALSE) { /* EOF - close this fd */ @fclose($fd); $sck = NULL; $console->debugger = NULL; $console->writeln("Debugger Disconnected"); } } elseif ($fd_name == 'listen') { /* accept the incomming connection */