本文整理汇总了PHP中readline_completion_function函数的典型用法代码示例。如果您正苦于以下问题:PHP readline_completion_function函数的具体用法?PHP readline_completion_function怎么用?PHP readline_completion_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readline_completion_function函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* @brief Read a line, optionally setting the completer
*
* @param string $prompt The prompt to display
* @param ReadlineAutoCompleter $completer The completer instance
* @param boolean $autohistory Add command to history automatically (default is false)
*/
static function read($prompt = null, ReadlineAutoCompleter $completer = null, $autohistory = false)
{
$oldcompleter = null;
// If we got an autocompleter, assign it
if ($completer) {
// Save a copy of the old completer if any
if (self::$completer && $completer !== self::$completer) {
$oldcompleter = self::$completer;
}
// Assign and set up the proxy call
self::$completer = $completer;
readline_completion_function(array('Readline', '_rlAutoCompleteProxy'));
}
// Read the line
$ret = readline($prompt);
// Restore old completer (if any) and add the command to the history
// if autohistory is enabled.
if ($oldcompleter) {
self::$completer = $oldcompleter;
}
if ($autohistory) {
self::addHistory($ret);
}
return $ret;
}
示例2: register
public function register()
{
if (!function_exists('readline_completion_function')) {
throw new \RuntimeException('require readline.');
}
readline_completion_function(array($this, 'callback'));
}
示例3: _initCompletion
protected static function _initCompletion()
{
self::$_readlineFile = sys_get_temp_dir() . '/phputils-data-history';
// init read line
readline_info('readline_name', 'data');
readline_completion_function([__CLASS__, 'readlineCompletion']);
is_file(self::$_readlineFile) and readline_read_history(self::$_readlineFile);
}
示例4: __construct
public function __construct($commands, OutputInterface $outputInterface, Client &$ociClient)
{
$this->commands = $commands;
$this->outputInterface = $outputInterface;
$this->client =& $ociClient;
$this->levels = [$this->commands['name']];
$this->currentLevel = $this->commands;
readline_completion_function([$this, 'readline_callback']);
}
示例5: __construct
public function __construct($hint)
{
$this->_curr_shh = $this->_shh;
$this->_hint = $hint;
$this->_history_file = getenv('HOME') . '/.htsh_history';
readline_completion_function(array($this, 'completionFunctor'));
$this->helpInit();
$this->handleSignals();
$this->restoreRC();
}
示例6: read
static function read($prompt = null)
{
if (self::$autocompleter != null) {
readline_completion_function(self::$autocompleter);
}
$ret = readline($prompt);
// if ($ret) return $ret;
// return true;
return $ret;
}
示例7: main
private function main()
{
\Cli::write(sprintf('Fuel %s - PHP %s (%s) (%s) [%s]', \Fuel::VERSION, phpversion(), php_sapi_name(), self::build_date(), PHP_OS));
// Loop until they break it
while (TRUE) {
if (\Cli::$readline_support) {
readline_completion_function(array(__CLASS__, 'tab_complete'));
}
if (!($__line = rtrim(trim(trim(\Cli::input('>>> ')), PHP_EOL), ';'))) {
continue;
}
if ($__line == 'quit') {
break;
}
// Add this line to history
//$this->history[] = array_slice($this->history, 0, -99) + array($line);
if (\Cli::$readline_support) {
readline_add_history($__line);
}
if (self::is_immediate($__line)) {
$__line = "return ({$__line})";
}
ob_start();
// Unset the previous line and execute the new one
$random_ret = \Str::random();
try {
$ret = eval("unset(\$__line); {$__line};");
} catch (\Exception $e) {
$ret = $random_ret;
$__line = $e->getMessage();
}
// Error was returned
if ($ret === $random_ret) {
\Cli::error('Parse Error - ' . $__line);
\Cli::beep();
}
if (ob_get_length() == 0) {
if (is_bool($ret)) {
echo $ret ? 'true' : 'false';
} elseif (is_string($ret)) {
echo addcslashes($ret, "....ÿ");
} elseif (!is_null($ret)) {
var_export($ret);
}
}
unset($ret);
$out = ob_get_contents();
ob_end_clean();
if (strlen($out) > 0 && substr($out, -1) != PHP_EOL) {
$out .= PHP_EOL;
}
echo $out;
unset($out);
}
}
示例8: readLine
public static function readLine($prompt, ReadlineCompleter $compl = null, callable $filter = null)
{
if ($compl) {
\readline_completion_function($compl);
}
$ret = \readline($prompt);
if (self::$history_file) {
readline_write_history(self::$history_file);
}
if ($filter) {
$ret = $filter($ret);
}
return $ret;
}
示例9: __construct
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->hasReadline = function_exists('readline');
$this->application = $container->get('ui.application');
$file = getenv('HOME') . '/.history_phpguard';
$this->historyFile = $file;
$this->output = $container->get('ui.output');
$this->container = $container;
// @codeCoverageIgnoreStart
if ($this->hasReadline) {
readline_read_history($this->historyFile);
readline_completion_function(array($this, 'autocompleter'));
}
// @codeCoverageIgnoreEnd
}
示例10: choose
/**
*
*
*/
public function choose($prompt, $choices)
{
echo $prompt . ": \n";
$choicesMap = array();
// Not an indexed array
if (!isset($choices[0])) {
$i = 0;
foreach ($choices as $choice => $value) {
$i++;
$choicesMap[$i] = $value;
echo "\t" . $i . " {$choice}\n";
}
} else {
foreach ($choices as $choice => $desc) {
$choicesMap[$choice] = $choice;
echo "\t{$choice}: {$desc}\n";
}
}
if ($this->style) {
echo $this->formatter->getStartMark($this->style);
}
$completionItems = array_keys($choicesMap);
$choosePrompt = "Please Choose 1-{$i} > ";
while (1) {
if (extension_loaded('readline')) {
$success = readline_completion_function(function ($string, $index) use($completionItems) {
return $completionItems;
});
$answer = readline($choosePrompt);
readline_add_history($answer);
} else {
echo $choosePrompt;
$answer = rtrim(fgets(STDIN), "\n");
}
$answer = (int) trim($answer);
if (is_integer($answer)) {
if (isset($choicesMap[$answer])) {
if ($this->style) {
echo $this->formatter->getClearMark();
}
return $choicesMap[$answer];
} else {
continue;
}
}
break;
}
}
示例11: run
/**
* Runs the shell.
*/
public function run()
{
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(true);
if ($this->hasReadline) {
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
}
$this->output->writeln($this->getHeader());
$php = null;
if ($this->processIsolation) {
$finder = new PhpExecutableFinder();
$php = $finder->find();
$this->output->writeln(<<<EOF
<info>Running with process isolation, you should consider this:</info>
* each command is executed as separate process,
* commands don't support interactivity, all params must be passed explicitly,
* commands output is not colorized.
EOF
);
}
while (true) {
$command = $this->readline();
if (false === $command) {
$this->output->writeln("\n");
break;
}
if ($this->hasReadline) {
readline_add_history($command);
readline_write_history($this->history);
}
if ($this->processIsolation) {
$pb = new ProcessBuilder();
$process = $pb->add($php)->add($_SERVER['argv'][0])->add($command)->inheritEnvironmentVariables(true)->getProcess();
$output = $this->output;
$process->run(function ($type, $data) use($output) {
$output->writeln($data);
});
$ret = $process->getExitCode();
} else {
$ret = $this->application->run(new StringInput($command), $this->output);
}
if (0 !== $ret) {
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
}
}
}
示例12: run
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";
}
示例13: cmdloop
function cmdloop($intro = false)
{
$this->preloop();
if ($this->completekey) {
readline_completion_function(array($this, 'complete'));
}
if ($intro) {
$this->intro = $intro;
}
if ($this->intro) {
fwrite($this->stdout, $this->intro . "\n");
}
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGINT, function () {
throw new Exception\KeyboardInterrupt();
});
}
$stop = null;
while (!$stop) {
if ($this->cmdqueue) {
$line = array_pop($this->cmdqueue);
} elseif ($this->completekey) {
$line = readline($this->prompt);
if ($line) {
readline_add_history($line);
} elseif ($line === false) {
$line = 'EOF';
}
} else {
fwrite($this->stdout, $this->prompt);
fflush($this->stdout);
$line = $this->stdin->readline();
if (!$line) {
$line = 'EOF';
} else {
$line = rtrim($line, "\r\n");
}
}
if (function_exists('pcntl_signal_dispatch')) {
pcntl_signal_dispatch();
}
$line = $this->precmd($line);
$stop = $this->onecmd($line);
$stop = $this->postcmd($stop, $line);
}
$this->postloop();
}
示例14: init
public static function init($paths = null, $history_path = null)
{
self::$_often = get_defined_functions();
self::$_often = array_merge(self::$_often['internal'], get_declared_classes());
if (is_null($paths)) {
$paths = explode(PATH_SEPARATOR, get_include_path());
}
self::$_paths = $paths;
if (self::_supportedReadline()) {
readline_completion_function(array(__CLASS__, 'autocomplete'));
self::$__last = null;
if (is_null($history_path)) {
if ($home = getenv('HOME')) {
$history_path = $home . '/.pprompt_history';
}
}
if (self::$__history_path = $history_path) {
readline_read_history(self::$__history_path);
}
}
unset($paths);
unset($history_path);
unset($home);
while (self::$__l = self::_readline(">> ")) {
if (self::_supportedReadline()) {
if (is_null(self::$__last) or self::$__l != self::$__last) {
readline_add_history(self::$__l);
}
if (self::$__history_path) {
readline_write_history(self::$__history_path);
}
}
try {
eval(self::$__l . ";");
echo "\n";
} catch (Exception $e) {
echo $e->getMessage() . "\n";
echo $e->getTraceAsString() . "\n";
}
self::$_vars = get_defined_vars();
self::$__last = self::$__l;
}
}
示例15: __construct
protected function __construct()
{
if (!empty($_SERVER['HOME'])) {
$this->historyFile = $_SERVER['HOME'] . '/.imc_history';
if (!file_exists($this->historyFile)) {
file_put_contents($this->historyFile, '');
}
readline_read_history($this->historyFile);
$this->history = explode(file_get_contents($this->historyFile), "\n");
if (isset($_ENV['HISTSIZE']) && $_ENV['HISTSIZE'] > 0) {
$this->histSize = $_ENV['HISTSIZE'];
}
}
readline_completion_function(array($this, 'completeCallback'));
register_shutdown_function(array($this, 'fatalErrorShutdown'));
# // Catch Ctrl+C, kill and SIGTERM
pcntl_signal(SIGTERM, array($this, 'sigintShutdown'));
pcntl_signal(SIGINT, array($this, 'sigintShutdown'));
}