本文整理汇总了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;
}
示例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;
}
示例3: addHistory
/**
* {@inheritDoc}
*/
public function addHistory($line)
{
if ($res = readline_add_history($line)) {
$this->writeHistory();
}
return $res;
}
示例4: readline_callback
private function readline_callback($line)
{
if ($line !== "") {
$this->buffer[] = $line;
readline_add_history($line);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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']);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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);
}
}