本文整理汇总了PHP中readline_read_history函数的典型用法代码示例。如果您正苦于以下问题:PHP readline_read_history函数的具体用法?PHP readline_read_history怎么用?PHP readline_read_history使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readline_read_history函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: setHistoryFile
public static function setHistoryFile($file)
{
if (file_exists($file)) {
readline_read_history($file);
}
self::$history_file = $file;
}
示例3: 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;
}
示例4: _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);
}
示例5: __construct
/**
* Constructor
*
* @return void
*/
public function __construct($options = array())
{
$this->input = fopen('php://stdin', 'r');
$this->rc_file = getenv('PHPREPLRC') ? getenv('PHPREPLRC') : getenv('HOME') . '/.phpreplrc';
$defaults = $this->defaultOptions();
$this->options = array_merge($defaults, $options);
if ($this->options['readline'] && is_readable($this->options['readline_hist'])) {
readline_read_history($this->options['readline_hist']);
}
}
示例6: execute
public function execute()
{
$dbw = wfGetDB(DB_MASTER);
if ($this->hasArg()) {
$fileName = $this->getArg();
$file = fopen($fileName, 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
$newPrompt = '> ';
$prompt = $newPrompt;
while (($line = Maintenance::readconsole($prompt)) !== false) {
if (!$line) {
# User simply pressed return key
continue;
}
$done = $dbw->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
$wholeLine .= ' ';
$prompt = ' -> ';
continue;
}
if ($useReadline) {
# Delimiter is eated by streamStatementEnd, we add it
# up in the history (bug 37020)
readline_add_history($wholeLine . $dbw->getDelimiter());
readline_write_history($historyFile);
}
try {
$res = $dbw->query($wholeLine);
$this->sqlPrintResult($res, $dbw);
$prompt = $newPrompt;
$wholeLine = '';
} catch (DBQueryError $e) {
$doDie = !Maintenance::posix_isatty(0);
$this->error($e, $doDie);
}
}
}
示例7: setUp
public function setUp()
{
if (!Libedit::isSupported()) {
$this->markTestSkipped('Libedit not enabled');
}
$this->historyFile = tempnam(sys_get_temp_dir(), 'psysh_test_history');
if (false === file_put_contents($this->historyFile, "_HiStOrY_V2_\n")) {
$this->fail('Unable to write history file: ' . $this->historyFile);
}
// Calling readline_read_history before readline_clear_history
// avoids segfault with PHP 5.5.7 & libedit v3.1
readline_read_history($this->historyFile);
readline_clear_history();
}
示例8: __construct
* Create a new ReadlineClient using $socket for communication.
*
* @param resource $socket
*/
public function __construct($socket)
{
$this->_socket = $socket;
}
/**
* Start the client with an prompt and readline history path.
*
* This method never returns.
*
* @param string $prompt
* @param string $historyFile
*/
public function start($prompt, $historyFile)
{
readline_read_history($historyFile);
declare (ticks=1);
pcntl_signal(SIGCHLD, SIG_IGN);
pcntl_signal(SIGINT, array($this, 'clear'), true);
// wait for the worker to finish executing hooks
if (fread($this->_socket, 1) != EvalWorker::READY) {
throw new \RuntimeException('EvalWorker failed to start');
}
$parser = new ShallowParser();
$buf = '';
$lineno = 1;
for (;;) {
$this->_clear = false;
$line = readline(sprintf('[%d] %s', $lineno, $buf == '' ? $prompt : str_pad('*> ', strlen($prompt), ' ', STR_PAD_LEFT)));
if ($this->_clear) {
$buf = '';
continue;
}
if (false === $line) {
$buf = 'exit(0);';
// ctrl-d acts like exit
}
if (strlen($line) > 0) {
readline_add_history($line);
}
$buf .= sprintf("%s\n", $line);
if ($statements = $parser->statements($buf)) {
++$lineno;
$buf = '';
foreach ($statements as $stmt) {
if (false === ($written = fwrite($this->_socket, $stmt))) {
throw new \RuntimeException('Socket error: failed to write data');
示例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: __construct
/**
* Constructor
*
* @return void
*/
public function __construct($options = array())
{
$this->input = fopen('php://stdin', 'r');
$this->rc_file = getenv('PHPREPLRC') ? getenv('PHPREPLRC') : getenv('HOME') . '/.phpreplrc';
$this->printers = $this->getDefaultPrinters();
$defaults = $this->getDefaultOptions();
$this->options = array_merge_recursive($defaults, $options);
$this->readline_support = true;
if (!function_exists('readline') || getenv('TERM') == 'dumb') {
$this->readline_support = false;
}
if ($this->readline_support && is_readable($this->getOption('readline_hist'))) {
readline_read_history($this->getOption('readline_hist'));
}
}
示例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: 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;
}
}
示例13: __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'));
}
示例14: execute
public function execute()
{
$dbw = wfGetDB(DB_MASTER);
if ($this->hasArg()) {
$fileName = $this->getArg();
$file = fopen($fileName, 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
while (($line = Maintenance::readconsole()) !== false) {
$done = $dbw->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
continue;
}
if ($useReadline) {
readline_add_history($wholeLine);
readline_write_history($historyFile);
}
try {
$res = $dbw->query($wholeLine);
$this->sqlPrintResult($res, $dbw);
$wholeLine = '';
} catch (DBQueryError $e) {
$this->error($e, true);
}
}
}
示例15: run
/**
* Runs the shell.
*/
public function run()
{
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(true);
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
$this->output->writeln($this->getHeader());
while (true) {
$command = readline($this->application->getName() . ' > ');
if (false === $command) {
$this->output->writeln("\n");
break;
}
readline_add_history($command);
readline_write_history($this->history);
if (0 !== ($ret = $this->application->run(new StringInput($command), $this->output))) {
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
}
}
}