Trait termwiz::lineedit::LineEditorHost
source · [−]pub trait LineEditorHost {
fn history(&mut self) -> &mut dyn History;
fn render_prompt(&self, prompt: &str) -> Vec<OutputElement>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
fn render_preview(&self, _line: &str) -> Vec<OutputElement>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
fn highlight_line(
&self,
line: &str,
cursor_position: usize
) -> (Vec<OutputElement>, usize) { ... }
fn complete(
&self,
_line: &str,
_cursor_position: usize
) -> Vec<CompletionCandidate>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
fn resolve_action(
&mut self,
_event: &InputEvent,
_editor: &mut LineEditor<'_>
) -> Option<Action> { ... }
}
Expand description
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
as NopLineEditorHost
.
Required Methods
Provided Methods
Given a prompt string, return the rendered form of the prompt as
a sequence of OutputElement
instances.
The implementation is free to interpret the prompt string however
it chooses; for instance, the application can opt to expand its own
application specific escape sequences as it sees fit.
The OutputElement
type allows returning graphic attribute changes
as well as textual output.
The default implementation returns the prompt as-is with no coloring
and no textual transformation.
Given a reference to the current line being edited, render a preview of its outcome. The preview is cleared when the input is accepted, or canceled.
fn highlight_line(
&self,
line: &str,
cursor_position: usize
) -> (Vec<OutputElement>, usize)
fn highlight_line(
&self,
line: &str,
cursor_position: usize
) -> (Vec<OutputElement>, usize)
Given a reference to the current line being edited and the position
of the cursor, return the rendered form of the line as a sequence
of OutputElement
instances.
While this interface technically allows returning arbitrary Text sequences,
the application should preserve the column positions of the graphemes,
otherwise the terminal cursor position won’t match up to the correct
location.
The OutputElement
type allows returning graphic attribute changes
as well as textual output.
The default implementation returns the line as-is with no coloring.
Tab completion support. The line and current cursor position are provided and it is up to the embedding application to produce a list of completion candidates. The default implementation is an empty list.
fn resolve_action(
&mut self,
_event: &InputEvent,
_editor: &mut LineEditor<'_>
) -> Option<Action>
fn resolve_action(
&mut self,
_event: &InputEvent,
_editor: &mut LineEditor<'_>
) -> Option<Action>
Allows the embedding application an opportunity to override or
remap keys to alternative actions.
Return None
to indicate that the default keymap processing
should occur.
Otherwise return an Action
enum variant indicating the action
that should be taken.
Use Some(Action::NoAction)
to indicate that no action should be taken.
editor
is provided so that your application can implement custom
actions and apply them to the editor buffer. Use LineEditor::get_line_and_cursor
and LineEditor::set_line_and_cursor
for that and return Some(Action::NoAction)
to prevent any default action from being taken.