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§
- Basic
History - A simple history implementation that holds entries in memory.
- Completion
Candidate - 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”. - Line
Edit Buffer - Line
Editor - The
LineEditorstruct provides line editing facilities similar to those in the unix shell. - NopLine
Editor Host - A concrete implementation of
LineEditorHostthat uses the default behaviors. - Search
Result
Enums§
- Action
- Movement
- Output
Element - The
OutputElementtype allows returning graphic attribute changes as well as textual output. - Search
Direction - Encodes the direction the search should take, relative to the current HistoryIndex.
- Search
Style
Traits§
- History
- Defines the history interface for the line editor.
- Line
Editor Host - The
LineEditorHosttrait allows an embedding application to influence how the line editor functions. A concrete implementation of the host with neutral defaults is provided asNopLineEditorHost.
Functions§
- line_
editor_ terminal - Create a
Terminalwith the recommended settings for use with aLineEditor.
Type Aliases§
- History
Index - Represents a position within the history. Smaller numbers are assumed to be before larger numbers, and the indices are assumed to be contiguous.
- Repeat
Count