| 1 | module readline |
| 2 | |
| 3 | #const $readline = require('readline') |
| 4 | |
| 5 | struct Termios {} |
| 6 | |
| 7 | // Only use standard os.get_line |
| 8 | // Need implementation for readline capabilities |
| 9 | // |
| 10 | // read_line_utf8 blocks execution in a loop and awaits user input |
| 11 | // characters from a terminal until `EOF` or `Enter` key is encountered |
| 12 | // in the input stream. |
| 13 | // read_line_utf8 returns the complete UTF-8 input line as an UTF-32 encoded `[]rune` or |
| 14 | // an error if the line is empty. |
| 15 | // The `prompt` `string` is output as a prefix text for the input capturing. |
| 16 | // read_line_utf8 is the main method of the `readline` module and `Readline` struct. |
| 17 | |
| 18 | pub fn (mut r Readline) read_line(prompt string) !string { |
| 19 | res := '' |
| 20 | print(prompt) |
| 21 | #const rl = $readline.createInterface({input: $process.stdin,output: $process.stdout,prompt: prompt.str}) |
| 22 | #rl.prompt() |
| 23 | #rl.on('line', function (ans) { rl.prompt(); res.str = ans; rl.close();}) |
| 24 | |
| 25 | return res |
| 26 | } |
| 27 | |
| 28 | pub fn read_line(prompt string) !string { |
| 29 | mut r := Readline{} |
| 30 | s := r.read_line(prompt)! |
| 31 | return s |
| 32 | } |
| 33 | |