mirror of
https://github.com/kanaka/mal.git
synced 2024-10-27 14:52:16 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
if (php_sapi_name() == "cli") {
|
|
$HISTORY_FILE = $_SERVER['HOME'] . "/.mal-history";
|
|
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;
|
|
}
|
|
} else {
|
|
function mal_readline($prompt) {}
|
|
}
|
|
|
|
?>
|