if (CONSOLE_INTERACTIVE) {
if (CONSOLE_READLINE) {
$line = readline($prompt);
- readline_add_history($line);
- if (defined('CONSOLE_HISTORY')) {
- // Save often; it's easy to hit fatal errors.
- readline_write_history(CONSOLE_HISTORY);
+ if (trim($line) != '') {
+ readline_add_history($line);
+ if (defined('CONSOLE_HISTORY')) {
+ // Save often; it's easy to hit fatal errors.
+ readline_write_history(CONSOLE_HISTORY);
+ }
}
return $line;
} else {
*/
function readline_emulation($prompt)
{
- if(file_exists(trim(shell_exec('which bash')))) {
+ if(CONSOLE_INTERACTIVE && file_exists(trim(shell_exec('which bash')))) {
$encPrompt = escapeshellarg($prompt);
$command = "read -er -p $encPrompt && echo \"\$REPLY\"";
$encCommand = escapeshellarg($command);
if (feof(STDIN)) {
return false;
}
- print $prompt;
+ if (CONSOLE_INTERACTIVE) {
+ print $prompt;
+ }
return fgets(STDIN);
}
print "Type ctrl+D or enter 'exit' to exit.\n";
}
-
-print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
-$prompt = common_config('site', 'name') . '> ';
+if (CONSOLE_INTERACTIVE) {
+ print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
+ $prompt = common_config('site', 'name') . '> ';
+} else {
+ $prompt = '';
+}
while (!feof(STDIN)) {
$line = read_input_line($prompt);
if ($line === false) {
- print "\n";
+ if (CONSOLE_INTERACTIVE) {
+ print "\n";
+ }
break;
} elseif ($line !== '') {
try {
print get_class($e) . ": " . $e->getMessage() . "\n";
}
}
- print "\n";
+ if (CONSOLE_INTERACTIVE) {
+ print "\n";
+ }
}