当前位置: 首页>>代码示例>>PHP>>正文


PHP readline_completion_function函数代码示例

本文整理汇总了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;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:32,代码来源:console.php

示例2: register

 public function register()
 {
     if (!function_exists('readline_completion_function')) {
         throw new \RuntimeException('require readline.');
     }
     readline_completion_function(array($this, 'callback'));
 }
开发者ID:y-yamagata,项目名称:psysh-laravel,代码行数:7,代码来源:Complementer.php

示例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);
 }
开发者ID:ligro,项目名称:php-utils,代码行数:8,代码来源:cli.php

示例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']);
 }
开发者ID:lukebeer,项目名称:broadworks-ocip,代码行数:9,代码来源:Console.php

示例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();
 }
开发者ID:kitech,项目名称:triline,代码行数:10,代码来源:htshc.php

示例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;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:10,代码来源:readline.php

示例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);
     }
 }
开发者ID:highestgoodlikewater,项目名称:webspider-1,代码行数:55,代码来源:console.php

示例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;
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:14,代码来源:conio.php

示例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
 }
开发者ID:phpguard,项目名称:phpguard,代码行数:18,代码来源:Shell.php

示例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;
     }
 }
开发者ID:arunahk,项目名称:CLIFramework,代码行数:52,代码来源:Chooser.php

示例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));
            }
        }
    }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:51,代码来源:Shell.php

示例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";
 }
开发者ID:robebeye,项目名称:PHPCliWrapper,代码行数:16,代码来源:Cli.php

示例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();
 }
开发者ID:iHunt101,项目名称:phlite,代码行数:47,代码来源:Cmd.php

示例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;
     }
 }
开发者ID:yslbc,项目名称:twcompany,代码行数:43,代码来源:Prompt.php

示例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'));
 }
开发者ID:reillo,项目名称:mdg_imc,代码行数:19,代码来源:imc.php


注:本文中的readline_completion_function函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。