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:
Keystroke | Action |
---|---|
Ctrl-A, Home | Move cursor to the beginning of the line |
Ctrl-E, End | Move cursor to the end of the line |
Ctrl-B, Left | Move cursor one grapheme to the left |
Ctrl-C | Cancel the line editor |
Ctrl-D | Cancel the line editor with an End-of-File result |
Ctrl-F, Right | Move cursor one grapheme to the right |
Ctrl-H, Backspace | Delete the grapheme to the left of the cursor |
Delete | Delete the grapheme to the right of the cursor |
Ctrl-J, Ctrl-M, Enter | Finish line editing and accept the current line |
Ctrl-K | Delete from cursor to end of line |
Ctrl-L | Move the cursor to the top left, clear screen and repaint |
Ctrl-R | Incremental history search mode |
Ctrl-W | Delete word leading up to cursor |
Alt-b, Alt-Left | Move the cursor backwards one word |
Alt-f, Alt-Right | Move 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 asNopLineEditorHost
.
Functions§
- Create a
Terminal
with the recommended settings for use with aLineEditor
.
Type Aliases§
- Represents a position within the history. Smaller numbers are assumed to be before larger numbers, and the indices are assumed to be contiguous.