Skip to main content

Crate rustline

Crate rustline 

Source
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 insert

Structs§

CommandCompleter
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.
FileCompleter
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§

RustlineError
Errors produced while reading a line.

Traits§

CompletionProvider
Supplies completions for a line and cursor position.
HintProvider
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 s in terminal columns, skipping ANSI escape sequences.
format_columns
Formats candidates into columns that fit within width terminal columns.
history_path
Derives the conventional history path for a program name.
is_separator
Returns true if c separates 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.