Trait pomprt::Editor

source ·
pub trait Editor {
    // Provided methods
    fn next_event(&mut self, input: &mut Reader<impl Read>) -> Result<Event> { ... }
    fn insert(&self, buffer: &mut String, cursor: &mut usize, c: char) { ... }
    fn complete(&self, buffer: &str, cursor: usize) -> Option<Completion> { ... }
    fn indent(&self, buffer: &mut String, cursor: &mut usize) { ... }
    fn highlight(&self, buffer: &str) -> String { ... }
    fn highlight_prompt(&self, prompt: &str, multiline: bool) -> String { ... }
    fn hint(&self, buffer: &str) -> Option<String> { ... }
    fn highlight_hint(&self, hint: &str) -> String { ... }
    fn is_multiline(&self, buffer: &str, cursor: usize) -> bool { ... }
    fn is_keyword(c: char) -> bool { ... }
}
Expand description

Custom editor behaviour for a Prompt

All functions provided may be overrided with custom ones. For instance, colors may be added by implementing Editor::highlight. Detailed examples can be found in the examples directory.

Provided Methods§

source

fn next_event(&mut self, input: &mut Reader<impl Read>) -> Result<Event>

Reads ANSI sequences from input and returns an editor event

source

fn insert(&self, buffer: &mut String, cursor: &mut usize, c: char)

Inserts a character at the current cursor position, moving it forward

Note that cursor should always lie inside a char boundary. This can usually be achieved by adding char::len_utf8 to it, instead of adding just 1 to move it forward.

source

fn complete(&self, buffer: &str, cursor: usize) -> Option<Completion>

Provides completion if available

Returning Some will cause Event::Tab to cycle through all results in the Vec, replacing buffer[start..end] until another key is pressed. Otherwise, Editor::indent is called.

source

fn indent(&self, buffer: &mut String, cursor: &mut usize)

Inserts indentation at the current cursor position when Editor::complete returns none

source

fn highlight(&self, buffer: &str) -> String

Highlights the current input by adding ANSI color sequences

See also Editor::highlight_prompt and Editor::highlight_hint

§Implementation notes

The returned string should have the same length when displayed (including whitespace), so only “invisible” sequences like SGR should be added.

source

fn highlight_prompt(&self, prompt: &str, multiline: bool) -> String

Highlights the current prompt

See Editor::highlight for more information

source

fn hint(&self, buffer: &str) -> Option<String>

Returns a hint for the current input, if available

This hint will be shown on the next line

source

fn highlight_hint(&self, hint: &str) -> String

Highlights the current hint

See Editor::highlight for more information

source

fn is_multiline(&self, buffer: &str, cursor: usize) -> bool

Returns true if the current input should be continued on another line

source

fn is_keyword(c: char) -> bool

Returns true if the given character is a word character

Object Safety§

This trait is not object safe.

Implementors§