change syntax of readline functions

This commit is contained in:
Pekka Laiho 2020-10-18 14:45:49 +07:00
parent 06acb47c72
commit 1e33e4d146
3 changed files with 9 additions and 9 deletions

View File

@ -236,9 +236,9 @@ fflush | `(fflush f)` | `true` | Persist buffered writes to disk for a file res
fread | `(fread f 16)` | `"abc"` | Read from 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. 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). 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). readline-add | `(readline-add "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). readline-load | `(readline-load "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). readline-save | `(readline-save "historyfile")` | `true` | Write readline history into file using [readline_write_history](https://www.php.net/manual/en/function.readline-write-history.php).
### Json functions ### Json functions

View File

@ -42,12 +42,12 @@
;; Define a file for readline and load it ;; Define a file for readline and load it
(def readlineFile (str HOME "calc_history")) (def readlineFile (str HOME "calc_history"))
(readlineLoad readlineFile) (readline-load readlineFile)
;; Main loop: Read input from user, add it to readline, and parse it ;; Main loop: Read input from user, add it to readline, and parse it
(def mainLoop (fn () (let (inp (readline "> ")) (def mainLoop (fn () (let (inp (readline "> "))
(do (readlineAdd inp) (do (readline-add inp)
(readlineSave readlineFile) (readline-save readlineFile)
(print (str (parseInput inp) EOL)) (print (str (parseInput inp) EOL))
true)))) true))))

View File

@ -72,15 +72,15 @@ class IO implements ILib
fn ($prompt = null) => readline($prompt) fn ($prompt = null) => readline($prompt)
)); ));
$env->set('readlineAdd', new CoreFunc('readlineAdd', 'Add new line of input to history.', 1, 1, $env->set('readline-add', new CoreFunc('readline-add', 'Add new line of input to history.', 1, 1,
fn (string $line) => readline_add_history($line) fn (string $line) => readline_add_history($line)
)); ));
$env->set('readlineLoad', new CoreFunc('readlineLoad', 'Load the history for readline from a file.', 1, 1, $env->set('readline-load', new CoreFunc('readline-load', 'Load the history for readline from a file.', 1, 1,
fn (string $file) => readline_read_history($file) fn (string $file) => readline_read_history($file)
)); ));
$env->set('readlineSave', new CoreFunc('readlineSave', 'Save the readline history into a file.', 1, 1, $env->set('readline-save', new CoreFunc('readline-save', 'Save the readline history into a file.', 1, 1,
fn (string $file) => readline_write_history($file) fn (string $file) => readline_write_history($file)
)); ));
} }