Module readline
line reader library
Introduction#
The readline module is responsible for reading input from the user.
The readline module is what Hilbish uses to read input from the user,
including all the interactive features of Hilbish like history search,
syntax highlighting, everything. The global Hilbish readline instance
is usable at hilbish.editor.
Customizing hilbish.editor is the common path. Creating a custom readline instance
is only needed when you want a fully separate line reader.
hilbish.editor:setHinter(function(line, pos)
if line == '' then return end
return ' (type something!)'
end)
Functions#
readline.fuzzySearch(needle, haystack) -> table: Performs a fuzzy search of needle in haystack and returns matched strings.readline.new() -> Readline: Creates a new readline instance.readline.newHistory(path) -> table: Creates a file-backed history handler.
fuzzySearch#
readline.fuzzySearch(needle, haystack) -> table
Since: 3.0.0
Performs a fuzzy search of needle in haystack and returns matched strings.
Parameters#
string needle
table haystack
Returns#
table
new#
readline.new() -> Readline
Since: 3.0.0
Creates a new readline instance.
Returns#
Readline
newHistory#
readline.newHistory(path) -> table
Since: 3.0.0
Creates a file-backed history handler.
Parameters#
string path
Returns#
table
function add
The add handler, which adds a line to the history.
function get
Gets a command line from the history based on the index passed to it.
function size
Returns the size of the history, how many commands the history has.
function clear
Clears the history.
See also#
Types#
Readline#
Methods#
deleteByAmount#
readline:deleteByAmount(amount)
Since: 3.0.0
Deletes characters in the line by the given amount.
Parameters#
number amount
getLine#
readline:getLine() -> string
Since: 3.0.0
Returns the current input line.
Returns#
string
getRegister#
readline:getRegister(register) -> string
Since: 3.0.0
Returns the text that is at the register.
Parameters#
string register
Returns#
string
insert#
readline:insert(text)
Since: 3.0.0
Inserts text into the Hilbish command line.
Parameters#
string text
log#
readline:log()
Since: 3.0.0
Prints a message before the prompt without it being interrupted by user input.
prompt#
readline:prompt()
Since: 3.0.0
Sets the prompt of the line reader. This is the text that shows up before user input.
read#
readline:read() -> string?
Since: 3.0.0
Reads input from the user.
Returns#
string? OptionalThrows an error if the user hits Ctrl-D or another error occurs.
readChar#
readline:readChar() -> string
Since: 3.0.0
Reads a keystroke from the user. This is in a format of something like Modifier-Key, like Ctrl-L.
Returns#
string
refreshPrompt#
readline:refreshPrompt()
Since: 3.0.0
Refreshes the prompt, if the text has been updated.
This is called automatically on hilbish.prompt
setCompleter#
readline:setCompleter(fn)
Since: 3.0.0
Sets the tab completion handler.
Parameters#
fun(line:string,pos:integer):table,string fn
setHighlighter#
readline:setHighlighter(fn)
Since: 3.0.0
Sets the syntax highlighter function. Called on every key insert to style the input.
Parameters#
fun(line:string):string fn
setHinter#
readline:setHinter(fn)
Since: 3.0.0
Sets the hinter function. Called on every key insert to provide inline hint text.
Parameters#
fun(line:string,pos:integer):string fn
setHistory#
readline:setHistory(handler)
Since: 3.0.0
Sets the history handler. Use newHistory(path) to get a file-backed handler, or supply your own.
Parameters#
table handler
function add
function get
function size
function clear
setInputMode#
readline:setInputMode(mode)
Since: 3.0.0
Sets the input mode.
Parameters#
string mode
Either emacs or vim.
setRawInputCallback#
readline:setRawInputCallback(fn)
Since: 3.0.0
Sets a function to be called on every raw input event (each keystroke). fn receives the input string.
Parameters#
function fn
setRegister#
readline:setRegister(register, text)
Since: 3.0.0
Sets the vim register at register to hold the passed text.
Parameters#
string register
string text
setSearcher#
readline:setSearcher(fn)
Since: 3.0.0
Sets the searcher used for history search and completion filtering. fn receives (needle string, haystack table) and returns a table of results, or nil to fall back to the default regex searcher.
Parameters#
fun(needle:string,haystack:table<string>):table|nil fn
setViActionCallback#
readline:setViActionCallback(fn)
Since: 3.0.0
Sets the function called when a Vim action occurs (yank, paste). fn receives (action string, args table).
Parameters#
function fn
setViModeCallback#
readline:setViModeCallback(fn)
Since: 3.0.0
Sets the function called when the Vim mode changes. fn receives the mode string: "insert", "normal", "delete", or "replace".
Parameters#
function fn