Struct termwiz::lineedit::LineEditor[][src]

pub struct LineEditor<'term> { /* fields omitted */ }

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

impl<'term> LineEditor<'term>[src]

pub fn new(terminal: &'term mut dyn Terminal) -> Self[src]

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)?;

pub fn set_prompt(&mut self, prompt: &str)[src]

pub fn read_line(
    &mut self,
    host: &mut dyn LineEditorHost
) -> Result<Option<String>>
[src]

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.

pub fn get_line_and_cursor(&mut self) -> (&str, usize)[src]

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.

pub fn set_line_and_cursor(&mut self, line: &str, cursor: usize)[src]

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.

pub fn apply_action(
    &mut self,
    host: &mut dyn LineEditorHost,
    action: Action
) -> Result<()>
[src]

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

impl<'term> !RefUnwindSafe for LineEditor<'term>

impl<'term> !Send for LineEditor<'term>

impl<'term> !Sync for LineEditor<'term>

impl<'term> Unpin for LineEditor<'term>

impl<'term> !UnwindSafe for LineEditor<'term>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.