2014-03-25 01:32:24 +04:00
|
|
|
<?php
|
|
|
|
|
2014-03-30 00:00:07 +04:00
|
|
|
$HISTORY_FILE = $_SERVER['HOME'] . "/.mal-history";
|
2014-03-25 01:32:24 +04:00
|
|
|
|
|
|
|
function mal_readline($prompt) {
|
|
|
|
global $HISTORY_FILE;
|
|
|
|
static $history_loaded = false;
|
|
|
|
|
|
|
|
// Load the history file
|
|
|
|
if (! $history_loaded) {
|
|
|
|
$history_loaded = true;
|
2015-03-12 06:22:35 +03:00
|
|
|
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);
|
2014-03-25 01:32:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$line = readline($prompt);
|
|
|
|
if ($line === false) { return NULL; }
|
|
|
|
readline_add_history($line);
|
|
|
|
|
|
|
|
// Append to the history file
|
2015-03-12 06:22:35 +03:00
|
|
|
if (is_writable($HISTORY_FILE)) {
|
|
|
|
if ($file = fopen($HISTORY_FILE, "a")) {
|
|
|
|
fputs($file, $line . "\n");
|
|
|
|
fclose($file);
|
|
|
|
}
|
2014-03-25 01:32:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $line;
|
|
|
|
}
|
|
|
|
|
2014-04-19 22:04:09 +04:00
|
|
|
?>
|