Module readline stdlib

readline
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
3
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Imported by

This section is empty.

Overview

The readline module lets 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.

Usage:

import readline

mut r := readline.Readline{}
answer := r.read_line('hello: ')!
println(answer)

or just:

import readline { read_line }

input := read_line('What is your name: ')!
println('Your name is: ${input}')

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn read_line

Windows
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 []rune 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

Linux
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 []rune 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

JavaScript
fn read_line(prompt string) !string

#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 []rune 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

Windows
fn read_line_utf8(prompt string) ![]rune

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 []rune 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).

#fn read_line_utf8

Linux
fn read_line_utf8(prompt string) ![]rune

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 []rune 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).

#fn read_line_utf8

fn read_line_utf8(prompt string) ![]rune

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 []rune 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).

Structs

#struct Readline

pub struct Readline {
mut:
	is_raw            bool
	orig_termios      termios.Termios // Linux
	current           []rune // Line being edited
	cursor            int    // Cursor position
	overwrite         bool
	cursor_row_offset int
	prompt            string
	prompt_offset     int
	previous_lines    [][]rune
	skip_empty        bool // skip the empty lines when calling .history_previous()
	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_utf8

fn (mut r &Readline) read_line_utf8(prompt string) ![]rune

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 []rune 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.

#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 []rune returned by read_line_utf8).

#fn (&Readline) enable_raw_mode

Linux
fn (mut r &Readline) enable_raw_mode()

enable_raw_mode enables the raw mode of the terminal.

In raw mode all key presses are directly sent to the program and no interpretation is done.

Please note that enable_raw_mode catches the SIGUSER (CTRL + C) signal.

For a method that does please see enable_raw_mode_nosig.

#fn (&Readline) enable_raw_mode_nosig

Linux
fn (mut r &Readline) enable_raw_mode_nosig()

enable_raw_mode_nosig enables the raw mode of the terminal.

In raw mode all key presses are directly sent to the program and no interpretation is done.

Please note that enable_raw_mode_nosig does not catch the SIGUSER (CTRL + C) signal as opposed to enable_raw_mode.

#fn (&Readline) disable_raw_mode

Linux
fn (mut r &Readline) disable_raw_mode()

disable_raw_mode disables the raw mode of the terminal.

For a description of raw mode please see the enable_raw_mode method.

#fn (&Readline) read_char

Linux
fn (r &Readline) read_char() !int

read_char reads a single character.

#fn (&Readline) analyse

Linux
fn (r &Readline) analyse(c int) Action

analyse returns an Action based on the type of input byte given in c.

#fn (&Readline) analyse_control

Linux
fn (r &Readline) analyse_control() Action

analyse_control returns an Action based on the type of input read by read_char.

#fn (&Readline) analyse_extended_control

Linux
fn (r &Readline) analyse_extended_control() Action

analyse_extended_control returns an Action based on the type of input read by read_char.

analyse_extended_control specialises in cursor control.

#fn (&Readline) analyse_extended_control_no_eat

Linux
fn (r &Readline) analyse_extended_control_no_eat(last_c u8) Action

analyse_extended_control_no_eat returns an Action based on the type of input byte given in c.

analyse_extended_control_no_eat specialises in detection of delete and insert keys.

#fn (&Readline) execute

Linux
fn (mut r &Readline) execute(a Action, c int) bool

execute executes the corresponding methods on Readline based on a Action and c int arguments.

#fn (&Readline) refresh_line

Linux
fn (mut r &Readline) refresh_line()

refresh_line redraws the current line, including the prompt.

#fn (&Readline) eof

Linux
fn (mut r &Readline) eof() bool

eof ends the line without a newline.

#fn (&Readline) insert_character

Linux
fn (mut r &Readline) insert_character(c int)

insert_character inserts the character c at current cursor position.

#fn (&Readline) delete_character

Linux
fn (mut r &Readline) delete_character()

Removes the character behind cursor.

#fn (&Readline) suppr_character

Linux
fn (mut r &Readline) suppr_character()

suppr_character removes (suppresses) the character in front of the cursor.

#fn (&Readline) commit_line

Linux
fn (mut r &Readline) commit_line() bool

commit_line adds a line break and then stops the main loop.

#fn (&Readline) move_cursor_left

Linux
fn (mut r &Readline) move_cursor_left()

move_cursor_left moves the cursor relative one cell to the left.

#fn (&Readline) move_cursor_right

Linux
fn (mut r &Readline) move_cursor_right()

move_cursor_right moves the cursor relative one cell to the right.

#fn (&Readline) move_cursor_begining

Linux
fn (mut r &Readline) move_cursor_begining()

move_cursor_begining moves the cursor to the beginning of the current line.

#fn (&Readline) move_cursor_end

Linux
fn (mut r &Readline) move_cursor_end()

move_cursor_end moves the cursor to the end of the current line.

#fn (&Readline) is_break_character

Linux
fn (r &Readline) is_break_character(c string) bool

is_break_character returns true if the character is considered as a word-breaking character.

#fn (&Readline) move_cursor_word_left

Linux
fn (mut r &Readline) move_cursor_word_left()

move_cursor_word_left moves the cursor relative one word length worth to the left.

#fn (&Readline) move_cursor_word_right

Linux
fn (mut r &Readline) move_cursor_word_right()

move_cursor_word_right moves the cursor relative one word length worth to the right.

#fn (&Readline) switch_overwrite

Linux
fn (mut r &Readline) switch_overwrite()

switch_overwrite toggles Readline overwrite mode on/off.

#fn (&Readline) clear_screen

Linux
fn (mut r &Readline) clear_screen()

clear_screen clears the current terminal window contents and positions the cursor at top left.

#fn (&Readline) history_previous

Linux
fn (mut r &Readline) history_previous()

history_previous sets current line to the content of the previous line in the history buffer.

#fn (&Readline) history_next

Linux
fn (mut r &Readline) history_next()

history_next sets current line to the content of the next line in the history buffer.

#fn (&Readline) suspend

Linux
fn (mut r &Readline) suspend()

suspend sends the SIGSTOP signal to the terminal.

Interfaces

This section is empty.

Enums

This section is empty.