mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add readline functions
This commit is contained in:
parent
656f805a5c
commit
d65fb5a58a
@ -234,6 +234,10 @@ fwrite | `(fwrite f "abc")` | `3` | Write to a file resource.
|
||||
fflush | `(fflush f)` | `true` | Persist buffered writes to disk for a file resource.
|
||||
fread | `(fread f 16)` | `"abc"` | Read from a file resource.
|
||||
feof? | `(feof? f)` | `true` | Return true if end of file has been reached for a file resource.
|
||||
readline | `(readline "What is your name? ")` | `What is your name? ` | Read line of user input using [readline](https://www.php.net/manual/en/function.readline.php).
|
||||
readlineAdd | `(readlineAdd "What is your name? ")` | `true` | Add line of user input to readline history using [readline_add_history](https://www.php.net/manual/en/function.readline-add-history.php).
|
||||
readlineLoad | `(readlineLoad "historyfile")` | `true` | Read readline history from file using [readline_read_history](https://www.php.net/manual/en/function.readline-read-history.php).
|
||||
readlineSave | `(readlineSave "historyfile")` | `true` | Write readline history into file using [readline_write_history](https://www.php.net/manual/en/function.readline-write-history.php).
|
||||
|
||||
### Json functions
|
||||
|
||||
|
@ -65,5 +65,23 @@ class IO implements ILib
|
||||
$env->set('feof?', new CoreFunc('feof?', 'Return true if end of file has been reached for a file resource.', 1, 1,
|
||||
fn ($handle) => @feof($handle)
|
||||
));
|
||||
|
||||
// Readline support
|
||||
|
||||
$env->set('readline', new CoreFunc('readline', 'Read line of user input.', 0, 1,
|
||||
fn ($prompt = null) => readline($prompt)
|
||||
));
|
||||
|
||||
$env->set('readlineAdd', new CoreFunc('readlineAdd', 'Add new line of input to history.', 1, 1,
|
||||
fn (string $line) => readline_add_history($line)
|
||||
));
|
||||
|
||||
$env->set('readlineLoad', new CoreFunc('readlineLoad', 'Load the history for readline from a file.', 1, 1,
|
||||
fn (string $file) => readline_read_history($file)
|
||||
));
|
||||
|
||||
$env->set('readlineSave', new CoreFunc('readlineSave', 'Save the readline history into a file.', 1, 1,
|
||||
fn (string $file) => readline_write_history($file)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user