readline #

Readline

The readline module let you await and read user input from a terminal in an easy and structured manner.

The module provides an easy way to prompt the user for questions or even make a REPL or an embedded console.

Use readline.Readline if you want to include more advanced features such as history or simply use readline.read_line('Please confirm (y/n):') directly for one-off user interactions.

Usage

import readline { Readline }

Readline.read_line('Continue?: (y/n)')

fn read_line #

fn read_line(prompt string) ?string

read_line does the same as read_line_utf8 but returns user input as a string. (As opposed to ustring as returned by read_line_utf8). NOTE that this version of read_line is a standalone function without persistent functionalities (e.g. history).

fn read_line_utf8 #

fn read_line_utf8(prompt string) ?ustring

read_line_utf8 blocks execution in a loop and awaits user input characters from a terminal until EOF or Enter key is encountered in the input stream. read_line_utf8 returns the complete input line as an UTF-8 encoded ustring or an error if the line is empty. The prompt string is output as a prefix text for the input capturing. read_line_utf8 is the main method of the readline module and Readline struct. NOTE that this version of read_line_utf8 is a standalone function without persistent functionalities (e.g. history).

struct Readline #

struct Readline {
mut:
	is_raw            bool
	orig_termios      Termios
	current           ustring
	cursor            int
	overwrite         bool
	cursor_row_offset int
	prompt            string
	prompt_offset     int
	previous_lines    []ustring
	search_index      int
	is_tty            bool
}

Readline is the key struct for reading and holding user input via a terminal.

Example

import readline { Readline }

fn (Readline) read_line #

fn (mut r Readline) read_line(prompt string) ?string

read_line does the same as read_line_utf8 but returns user input as a string. (As opposed to ustring returned by read_line_utf8).

fn (Readline) read_line_utf8 #

fn (mut r Readline) read_line_utf8(prompt string) ?ustring

Only use standard os.get_line Need implementation for readline capabilities read_line_utf8 blocks execution in a loop and awaits user input characters from a terminal until EOF or Enter key is encountered in the input stream. read_line_utf8 returns the complete input line as an UTF-8 encoded ustring or an error if the line is empty. The prompt string is output as a prefix text for the input capturing. read_line_utf8 is the main method of the readline module and Readline struct.