pub trait Highlighter {
// Provided methods
fn highlight<'l>(&self, line: &'l str, pos: usize) -> Cow<'l, str> { ... }
fn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str> { ... }
fn highlight_dynamic_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str> { ... }
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { ... }
fn highlight_candidate<'c>(
&self,
candidate: &'c str,
completion: CompletionType,
) -> Cow<'c, str> { ... }
fn highlight_char(&self, grapheme: &str) -> bool { ... }
}
Expand description
Syntax highlighter with ansi color. Rustyline will try to handle escape sequence for ansi color on windows when not supported natively (windows <10).
Currently, the highlighted version must have the same display width as the original input.
Provided Methods§
Sourcefn highlight<'l>(&self, line: &'l str, pos: usize) -> Cow<'l, str>
fn highlight<'l>(&self, line: &'l str, pos: usize) -> Cow<'l, str>
Takes the currently edited line
with the cursor pos
ition and
returns the highlighted version (with ANSI color).
For example, you can implement blink-matching-paren.
Sourcefn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str>
fn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str>
Takes the prompt
and
returns the highlighted version (with ANSI color).
Sourcefn highlight_dynamic_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str>
👎Deprecated since 2.0.1: please use highlight_prompt
instead
fn highlight_dynamic_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str>
highlight_prompt
insteadTakes the dynamic prompt
and
returns the highlighted version (with ANSI color).
Sourcefn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str>
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str>
Takes the hint
and
returns the highlighted version (with ANSI color).
Sourcefn highlight_candidate<'c>(
&self,
candidate: &'c str,
completion: CompletionType,
) -> Cow<'c, str>
fn highlight_candidate<'c>( &self, candidate: &'c str, completion: CompletionType, ) -> Cow<'c, str>
Takes the completion canditate
and
returns the highlighted version (with ANSI color).
Currently, used only with CompletionType::List
.
Sourcefn highlight_char(&self, grapheme: &str) -> bool
fn highlight_char(&self, grapheme: &str) -> bool
Tells if the ch
ar needs to be highlighted when typed or when cursor
is moved under.
Used to optimize refresh when a character is inserted or the cursor is moved.