pub struct LineEditor<'term> { /* private fields */ }
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(())
}

Implementations

Create a new line editor. In most cases, you’ll want to use the line_editor function, because it creates a Terminal instance with the recommended settings, but if you need to decompose that for some reason, this snippet shows the recommended way to create a line editor:

use termwiz::caps::{Capabilities, ProbeHints};
use termwiz::terminal::new_terminal;
use termwiz::Error;
// Disable mouse input in the line editor
let hints = ProbeHints::new_from_env()
    .mouse_reporting(Some(false));
let caps = Capabilities::new_with_hints(hints)?;
let terminal = new_terminal(caps)?;

Enter line editing mode. Control is not returned to the caller until a line has been accepted, or until an error is detected. Returns Ok(None) if the editor was cancelled eg: via CTRL-C.

Returns the current line and cursor position. You don’t normally need to call this unless you are defining a custom editor operation on the line buffer contents. The cursor position is the byte index into the line UTF-8 bytes.

Sets the current line and cursor position. You don’t normally need to call this unless you are defining a custom editor operation on the line buffer contents. The cursor position is the byte index into the line UTF-8 bytes. Panics: the cursor must be within the bounds of the provided line.

Applies the effect of the specified action to the line editor. You don’t normally need to call this unless you are defining custom key mapping or custom actions in your embedding application.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.