[−][src]Trait rucline::completion::Completer
Completes the buffer in-line.
Whenever the line is edited, e.g. Write
or Delete
, the prompt
will ask the
Completer
for a possible completion to append to the current buffer. The implementation
may use the Buffer
to decide which completions are applicable.
When the Completer
is invoked, the buffer is not actually changed, the completion is
only rendered. A Complete
action must be issued to incorporate the completion into
the buffer.
Example
Basic implementation:
use rucline::Buffer; use rucline::completion::Completer; use std::borrow::Cow; struct Basic(Vec<String>); impl Completer for Basic { fn complete_for(&self, buffer: &Buffer) -> Option<Cow<'_, str>> { if buffer.is_empty() { None } else { self.0 .iter() .find(|completion| completion.starts_with(buffer.as_str())) .map(|completion| (&completion[buffer.len()..]).into()) } } }
See also
Required methods
fn complete_for(&self, buffer: &Buffer) -> Option<Cow<'_, str>>
Provides the in-line completion.
Whenever the line is edited, e.g. Write
or Delete
, the prompt
will call
complete_for
for a possible completion to append to the current buffer.
Arguments
buffer
- Read-only view into the line buffer, providing the context in which this event is happening.
Return
- A completion to be rendered.
None
if there are no suggestions.