diff options
author | Brion Vibber <brion@pobox.com> | 2009-11-17 17:09:31 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2009-11-17 17:09:31 -0800 |
commit | b7660b3d9998af4106795d53ed6bc1a0d77d7d4f (patch) | |
tree | 44789019bafad610ded89fe775a467c182122031 /scripts | |
parent | 88ff0eefb411e05e3d622861d90760c12bbba9f0 (diff) |
A little cleanup on console.php; save readline history more aggressively; avoid some notice sloppiness)
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/console.php | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/scripts/console.php b/scripts/console.php index 41dd43f28..210d2b6b2 100755 --- a/scripts/console.php +++ b/scripts/console.php @@ -29,19 +29,15 @@ ENDOFHELP; require_once INSTALLDIR.'/scripts/commandline.inc'; -if (function_exists('posix_isatty')) { - define('CONSOLE_INTERACTIVE', posix_isatty(0)); -} else { - // Windows? Assume we're on a terminal. :P - define('CONSOLE_INTERACTIVE', false); -} -if (CONSOLE_INTERACTIVE) { - define('CONSOLE_READLINE', function_exists('readline')); -} +// Assume we're on a terminal if on Windows, otherwise posix_isatty tells us. +define('CONSOLE_INTERACTIVE', !function_exists('posix_isatty') || posix_isatty(0)); +define('CONSOLE_READLINE', CONSOLE_INTERACTIVE && function_exists('readline')); -if (CONSOLE_READLINE && CONSOLE_INTERACTIVE && file_exists(CONSOLE_HISTORY)) { - define(CONSOLE_HISTORY, getenv("HOME") . "/.statusnet_console_history"); - readline_read_history(CONSOLE_HISTORY); +if (CONSOLE_READLINE && CONSOLE_INTERACTIVE) { + define('CONSOLE_HISTORY', getenv("HOME") . "/.statusnet_console_history"); + if (file_exists(CONSOLE_HISTORY)) { + readline_read_history(CONSOLE_HISTORY); + } } function read_input_line($prompt) @@ -50,6 +46,10 @@ function read_input_line($prompt) 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); + } return $line; } else { return readline_emulation($prompt); @@ -156,7 +156,3 @@ while (!feof(STDIN)) { } print "\n"; } - -if (CONSOLE_READLINE && CONSOLE_INTERACTIVE) { - @readline_write_history(CONSOLE_HISTORY); -} |