Expand description
A line editor for interactive terminal programs.
Rustline is a Rust port of bestline, which is itself a fork of linenoise. It offers Emacs-style editing, reverse history search, completion, hints and UTF-8 editing over ANSI X3.64 escape sequences, with no terminfo dependency.
§Quick start
let mut rl = rustline::Rustline::new();
loop {
match rl.readline("> ") {
Ok(line) => {
rl.add_history_entry(&line);
println!("{line}");
}
Err(rustline::RustlineError::Interrupted) => continue,
Err(rustline::RustlineError::Eof) => break,
Err(e) => return Err(e),
}
}§Key bindings
CTRL-A / HOME start of line CTRL-T transpose chars
CTRL-E / END end of line ALT-T transpose words
CTRL-B / LEFT back one char ALT-U uppercase word
CTRL-F / RIGHT forward one char ALT-L lowercase word
ALT-B back one word ALT-C capitalize word
ALT-F forward one word ALT-\ squeeze whitespace
ALT-LEFT back one expr CTRL-K kill to end
ALT-RIGHT forward one expr CTRL-U kill to start
CTRL-P / UP previous history CTRL-W / ALT-H kill word backwards
CTRL-N / DOWN next history ALT-D kill word forwards
ALT-< oldest history CTRL-Y yank
ALT-> newest history ALT-Y rotate ring and yank
CTRL-R search history CTRL-SPACE set mark
CTRL-G cancel search CTRL-X CTRL-X go to mark
CTRL-H / BKSP backspace CTRL-L clear screen
CTRL-D delete, or EOF CTRL-C interrupt
TAB complete CTRL-Z suspend
ALT-SHIFT-B barf expression CTRL-\ quit
ALT-SHIFT-S slurp expression CTRL-S / CTRL-Q flow control
CTRL-J new line CTRL-Q escaped insertStructs§
- Command
Completer - Completes a fixed list of words at the start of a line, delegating anything later in the line to another provider.
- Completions
- Candidate completions for a position in a line.
- Config
- Editor behaviour that a caller may want to change.
- File
Completer - Completes filesystem paths, including
~expansion. - Hint
- Text to display after the cursor, with the escape sequences that colour it.
- History
- Ring of previously entered lines, oldest first.
- NoCompleter
- A provider that never completes anything.
- NoHinter
- A provider that never hints.
- Rustline
- A line editor.
- WinSize
- Size of the terminal window in character cells.
Enums§
- Rustline
Error - Errors produced while reading a line.
Traits§
- Completion
Provider - Supplies completions for a line and cursor position.
- Hint
Provider - Supplies a hint for the line being edited.
Functions§
- char_
width - Number of terminal columns occupied by
c. - clear_
screen - Clears the terminal and moves the cursor to the top left.
- display_
width - Monospace width of
sin terminal columns, skipping ANSI escape sequences. - format_
columns - Formats
candidatesinto columns that fit withinwidthterminal columns. - history_
path - Derives the conventional history path for a program name.
- is_
separator - Returns
trueifcseparates words. - readline
- Reads one line using a temporary editor.
- readline_
with_ history - Reads one line, loading and saving history at
~/.{prog}_history. - word_
start - Start of the shell-like word ending at
pos.
Type Aliases§
- Result
- Result alias used throughout the crate.