readline - read text input from the user
readline will read a line from the terminal and return it, using prompt as a prompt. If prompt is not provided, no prompt is issued. If notrail is specified, the line returned has the final newline removed so only the text of the line remains.
readline offers editing capabilities while the user is entering the line. By default, the line editing commands are similar to those of emacs.
readline([prompt:string or number][, opts:table]): string
The recommended method of reading text input.
If prompt is specified, it will be displayed to the user. Otherwise, no prompt will be issued. If prompt is a number, readline will return that number of characters from standard input and return them without printing to the screen. If prompt is a table, it will be used in place of opts.
Available opts are:
pwchar = string,
history = table,
prompt = string,
arrows = boolean,
actions = table,
highlighter = function,
default, text = string,
complete, tab, tabact = function
All opts are optional. If opts.prompt is specified and no prompt is specified, opts.prompt will be used instead.
arrows specifies whether readline should act specially on arrow-key presses and defaults to true. actions, if specified, should have four fields: up:function, down:function, left:function, and right:function. These functions are called upon their corresponding arrow-key presses.
highlighter should either do nothing, or highlight the provided string using VT100 control codes. highlighter should always return a string. default and text each specify text the buffer should be initialized to; default takes precedence. complete, tab, tabact, and actions.tab are called when the [TAB] key is pressed; readline checks for each of these respectively.
If a [TAB]- or arrow-key-action returns the string "return", readline will return the contents of the current text buffer. If the [TAB]-action returns the string "return_none", readline will return only a newline ("\n").
In most cases, readline is the preferred method of retrieving keyboard input.
readline uses libvt(3) to get the current cursor position and screen resolution.
Monolith System Interfaces (c) 2020 Ocawesome101 under the GNU GPLv3.
sh(1), login(1), io(3), libvt(3)