當前位置: 首頁>>代碼示例>>PHP>>正文


PHP readline_add_history函數代碼示例

本文整理匯總了PHP中readline_add_history函數的典型用法代碼示例。如果您正苦於以下問題:PHP readline_add_history函數的具體用法?PHP readline_add_history怎麽用?PHP readline_add_history使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了readline_add_history函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _getData

 protected static function _getData()
 {
     // todo detect if we are reading from stdin or pipe
     $data = readline("data > ");
     readline_add_history($data);
     return $data;
 }
開發者ID:ligro,項目名稱:php-utils,代碼行數:7,代碼來源:cli.php

示例2: mal_readline

function mal_readline($prompt)
{
    global $HISTORY_FILE;
    static $history_loaded = false;
    // Load the history file
    if (!$history_loaded) {
        $history_loaded = true;
        if (is_readable($HISTORY_FILE)) {
            if ($file = fopen($HISTORY_FILE, "r")) {
                while (!feof($file)) {
                    $line = fgets($file);
                    if ($line) {
                        readline_add_history($line);
                    }
                }
                fclose($file);
            }
        }
    }
    $line = readline($prompt);
    if ($line === false) {
        return NULL;
    }
    readline_add_history($line);
    // Append to the history file
    if (is_writable($HISTORY_FILE)) {
        if ($file = fopen($HISTORY_FILE, "a")) {
            fputs($file, $line . "\n");
            fclose($file);
        }
    }
    return $line;
}
開發者ID:mdkarch,項目名稱:mal,代碼行數:33,代碼來源:readline.php

示例3: addHistory

 /**
  * {@inheritDoc}
  */
 public function addHistory($line)
 {
     if ($res = readline_add_history($line)) {
         $this->writeHistory();
     }
     return $res;
 }
開發者ID:fulore,項目名稱:psysh,代碼行數:10,代碼來源:GNUReadline.php

示例4: readline_callback

 private function readline_callback($line)
 {
     if ($line !== "") {
         $this->buffer[] = $line;
         readline_add_history($line);
     }
 }
開發者ID:iTXTech,項目名稱:Genisys,代碼行數:7,代碼來源:CommandReader.php

示例5: start

 public function start()
 {
     $histfile = '.magesh_history';
     if (PHP_OS == 'Linux') {
         readline_read_history($histfile);
     }
     do {
         $input = $this->_getInput($this->_prompt);
         if ($input === false) {
             break;
         }
         $cmd = $this->_formatInput($input);
         if (PHP_OS == 'Linux') {
             readline_add_history($input);
             readline_write_history($histfile);
         }
         echo "\n";
         $result = null;
         try {
             $result = eval($cmd);
         } catch (Exception $e) {
             $result = $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n\n";
         }
         $output = $this->_formatOutput($result);
         echo "Result: " . $output . "\n\n";
     } while (true);
     return true;
 }
開發者ID:stolksdorf,項目名稱:mageshell,代碼行數:28,代碼來源:Mageshell.php

示例6: init

 protected function init()
 {
     global $swarmInstallDir;
     $this->checkAtty();
     $supportsReadline = function_exists('readline_add_history');
     if ($supportsReadline) {
         $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.testswarm_eval_history" : "{$swarmInstallDir}/config/.testswarm_eval_history";
         readline_read_history($historyFile);
     }
     while (!!($line = $this->cliInput())) {
         if ($supportsReadline) {
             readline_add_history($line);
             readline_write_history($historyFile);
         }
         $ret = eval($line . ";");
         if (is_null($ret)) {
             echo "\n";
         } elseif (is_string($ret) || is_numeric($ret)) {
             echo "{$ret}\n";
         } else {
             var_dump($ret);
         }
     }
     print "\n";
     exit;
 }
開發者ID:TestArmada,項目名稱:admiral,代碼行數:26,代碼來源:repl.php

示例7: writeHistory

 /**
  * {@inheritDoc}
  */
 public function writeHistory()
 {
     // We have to write history first, since it is used
     // by Libedit to list history
     $res = readline_write_history($this->historyFile);
     if (!$res || !$this->eraseDups && !$this->historySize > 0) {
         return $res;
     }
     $hist = $this->listHistory();
     if (!$hist) {
         return true;
     }
     if ($this->eraseDups) {
         // flip-flip technique: removes duplicates, latest entries win.
         $hist = array_flip(array_flip($hist));
         // sort on keys to get the order back
         ksort($hist);
     }
     if ($this->historySize > 0) {
         $histsize = count($hist);
         if ($histsize > $this->historySize) {
             $hist = array_slice($hist, $histsize - $this->historySize);
         }
     }
     readline_clear_history();
     foreach ($hist as $line) {
         readline_add_history($line);
     }
     return readline_write_history($this->historyFile);
 }
開發者ID:betes-curieuses-design,項目名稱:ElieJosiePhotographie,代碼行數:33,代碼來源:GNUReadline.php

示例8: getAuthorization

 public function getAuthorization()
 {
     /* try to get cached access token first */
     if (file_exists(".acc_tok_cache")) {
         while ($reuseAccTok != 'y' && $reuseAccTok != 'n') {
             $reuseAccTok = readline("Reuse cached access token (y/n)? ");
             readline_add_history($reuseAccTok);
         }
         if ($reuseAccTok == 'y') {
             $accTokenString = file_get_contents(".acc_tok_cache");
             $accessToken = unserialize($accTokenString);
             echo "Using access token: ";
             print_r($accessToken);
         }
     }
     /* no cached access token, get a new one */
     if (empty($accessToken)) {
         try {
             $reqToken = $this->oauth->getRequestToken($this->reqTokenURL);
         } catch (OAuthException $oae) {
             echo "The following exception occured when trying to get a request token: " . $oae->getMessage() . "\n";
         }
         print_r($reqToken);
         echo "Now you have to authorize the following token: " . $this->authorizeURL . "?oauth_token=" . $reqToken['oauth_token'] . "\n";
         $this->ssp_readline("Press any key to continue...\n");
         $accessToken = $reqToken;
         $this->oauth->setToken($reqToken['oauth_token'], $reqToken['oauth_token_secret']);
         $accessToken = $this->oauth->getAccessToken($this->accTokenURL);
         $accessTokenString = serialize($accessToken);
         file_put_contents(".acc_tok_cache", $accessTokenString);
     }
     $this->oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
 }
開發者ID:henrikau,項目名稱:confusa,代碼行數:33,代碼來源:OAuthRESTClient.php

示例9: readInput

 /**
  * Read a line from the command prompt
  * @return string
  */
 public function readInput()
 {
     $line = readline($this->prompt);
     if (!empty($line)) {
         readline_add_history($line);
     }
     return $line;
 }
開發者ID:g4z,項目名稱:poop,代碼行數:12,代碼來源:Shell.php

示例10: _read

 protected function _read($hint = null)
 {
     if (!extension_loaded('readline')) {
         throw new \Exception('`readline` extension is not loaded.');
     }
     $value = readline($hint);
     readline_add_history($value);
     return (string) $value;
 }
開發者ID:codespot,項目名稱:sprinter,代碼行數:9,代碼來源:ReadlineInput.php

示例11: in

 /**
  * in
  * 
  * @param string $text
  * @param boolean $escape
  * @return string
  */
 public static function in($text, $escape = false)
 {
     $line = readline($text);
     readline_add_history($line);
     if ($escape) {
         return escapeshellcmd($line);
     }
     return $line;
 }
開發者ID:bartekpie3,項目名稱:PhpConsole,代碼行數:16,代碼來源:Console.php

示例12: setCheckBlog

 public function setCheckBlog()
 {
     $GA = GreenArrow::greenArrow();
     echo "\n--------------------------------------------------------";
     echo "\nShould I check all BLOG pages? \n" . "\n[ 1 ] {$GA} YES" . "\n[ ENTER ] {$GA} NO, only '/blog/'\n";
     $checkBlog = readline("Your choice: ");
     readline_add_history($checkBlog);
     echo "--------------------------------------------------------";
     self::$checkBlog = $checkBlog;
 }
開發者ID:Kurets,項目名稱:origin,代碼行數:10,代碼來源:GetAllHrefs.php

示例13: readLine

 /**
  * @param string $prompt
  */
 public function readLine($prompt)
 {
     $configuration = $this->configuration;
     $line = trim(readline($prompt));
     $tokens = explode(' ', $line);
     if (!empty($tokens)) {
         $this->executeIfPossible($tokens, $configuration);
         readline_add_history($line);
     }
 }
開發者ID:bazzline,項目名稱:php_component_cli_readline,代碼行數:13,代碼來源:ReadLine.php

示例14: getInput

 public function getInput($label = "Please Enter", $callback = null)
 {
     $line = readline("{$label} : ");
     readline_add_history($line);
     if (is_object($callback) && is_callable($callback)) {
         call_user_func_array($callback, array($line));
     } else {
         return $line;
     }
 }
開發者ID:druto,項目名稱:framework,代碼行數:10,代碼來源:DrutoCli.php

示例15: 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


注:本文中的readline_add_history函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。