Expand description

The LineEditor struct provides line editing facilities similar to those in the unix shell.

use termwiz::lineedit::{line_editor_terminal, NopLineEditorHost, LineEditor};

fn main() -> termwiz::Result<()> {
    let mut terminal = line_editor_terminal()?;
    let mut editor = LineEditor::new(&mut terminal);
    let mut host = NopLineEditorHost::default();

    let line = editor.read_line(&mut host)?;
    println!("read line: {:?}", line);

    Ok(())
}

Key Bindings

The following key bindings are supported:

KeystrokeAction
Ctrl-A, HomeMove cursor to the beginning of the line
Ctrl-E, EndMove cursor to the end of the line
Ctrl-B, LeftMove cursor one grapheme to the left
Ctrl-CCancel the line editor
Ctrl-DCancel the line editor with an End-of-File result
Ctrl-F, RightMove cursor one grapheme to the right
Ctrl-H, BackspaceDelete the grapheme to the left of the cursor
DeleteDelete the grapheme to the right of the cursor
Ctrl-J, Ctrl-M, EnterFinish line editing and accept the current line
Ctrl-KDelete from cursor to end of line
Ctrl-LMove the cursor to the top left, clear screen and repaint
Ctrl-RIncremental history search mode
Ctrl-WDelete word leading up to cursor
Alt-b, Alt-LeftMove the cursor backwards one word
Alt-f, Alt-RightMove the cursor forwards one word

Structs

A simple history implementation that holds entries in memory.

A candidate for tab completion. If the line and cursor look like “why he” and if “hello” is a valid completion of “he” in that context, then the corresponding CompletionCandidate would have its range set to [4..6] (the “he” slice range) and its text set to “hello”.

The LineEditor struct provides line editing facilities similar to those in the unix shell.

A concrete implementation of LineEditorHost that uses the default behaviors.

Enums

The OutputElement type allows returning graphic attribute changes as well as textual output.

Encodes the direction the search should take, relative to the current HistoryIndex.

Traits

Defines the history interface for the line editor.

The LineEditorHost trait allows an embedding application to influence how the line editor functions. A concrete implementation of the host with neutral defaults is provided as NopLineEditorHost.

Functions

Create a Terminal with the recommended settings for use with a LineEditor.

Type Definitions

Represents a position within the history. Smaller numbers are assumed to be before larger numbers, and the indices are assumed to be contiguous.