Struct termwiz::lineedit::LineEditor
source · [−]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
sourceimpl<'term> LineEditor<'term>
impl<'term> LineEditor<'term>
sourcepub fn new(terminal: &'term mut dyn Terminal) -> Self
pub fn new(terminal: &'term mut dyn Terminal) -> Self
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)
sourcepub fn read_line(
&mut self,
host: &mut dyn LineEditorHost
) -> Result<Option<String>>
pub fn read_line(
&mut self,
host: &mut dyn LineEditorHost
) -> Result<Option<String>>
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.
sourcepub fn get_line_and_cursor(&mut self) -> (&str, usize)
pub fn get_line_and_cursor(&mut self) -> (&str, usize)
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.
sourcepub fn set_line_and_cursor(&mut self, line: &str, cursor: usize)
pub fn set_line_and_cursor(&mut self, line: &str, cursor: usize)
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.
sourcepub fn apply_action(
&mut self,
host: &mut dyn LineEditorHost,
action: Action
) -> Result<()>
pub fn apply_action(
&mut self,
host: &mut dyn LineEditorHost,
action: Action
) -> Result<()>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more