pub struct DefaultCompleter { /* private fields */ }Expand description
A default completer that can detect keywords
§Example
use reedline::{DefaultCompleter, Reedline};
let commands = vec![
"test".into(),
"hello world".into(),
"hello world reedline".into(),
"this is the reedline crate".into(),
];
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
let mut line_editor = Reedline::create().with_completer(completer);Implementations§
Source§impl DefaultCompleter
impl DefaultCompleter
Sourcepub fn new(external_commands: Vec<String>) -> Self
pub fn new(external_commands: Vec<String>) -> Self
Construct the default completer with a list of commands/keywords to highlight
Sourcepub fn new_with_wordlen(
external_commands: Vec<String>,
min_word_len: usize,
) -> Self
pub fn new_with_wordlen( external_commands: Vec<String>, min_word_len: usize, ) -> Self
Construct the default completer with a list of commands/keywords to highlight, given a minimum word length
Sourcepub fn insert(&mut self, words: Vec<String>)
pub fn insert(&mut self, words: Vec<String>)
Insert external_commands list in the object root
§Arguments
lineA vector ofStringcontaining the external commands
§Example
use reedline::{DefaultCompleter,Completer};
let mut completions = DefaultCompleter::default();
// Insert multiple words
completions.insert(vec!["a","line","with","many","words"].iter().map(|s| s.to_string()).collect());
// The above line is equal to the following:
completions.insert(vec!["a","line","with"].iter().map(|s| s.to_string()).collect());
completions.insert(vec!["many","words"].iter().map(|s| s.to_string()).collect());Sourcepub fn with_inclusions(incl: &[char]) -> Self
pub fn with_inclusions(incl: &[char]) -> Self
Create a new DefaultCompleter with provided non alphabet characters whitelisted.
The default DefaultCompleter will only parse alphabet characters (a-z, A-Z). Use this to
introduce additional accepted special characters.
§Arguments
inclAn array slice with allowed characters
§Example
use reedline::{DefaultCompleter,Completer,Span,Suggestion};
let mut completions = DefaultCompleter::default();
completions.insert(vec!["test-hyphen","test_underscore"].iter().map(|s| s.to_string()).collect());
assert_eq!(
completions.complete("te",2),
vec![Suggestion {value: "test".into(), description: None, extra: None, span: Span { start: 0, end: 2 }, append_whitespace: false}]);
let mut completions = DefaultCompleter::with_inclusions(&['-', '_']);
completions.insert(vec!["test-hyphen","test_underscore"].iter().map(|s| s.to_string()).collect());
assert_eq!(
completions.complete("te",2),
vec![
Suggestion {value: "test-hyphen".into(), description: None, extra: None, span: Span { start: 0, end: 2 }, append_whitespace: false},
Suggestion {value: "test_underscore".into(), description: None, extra: None, span: Span { start: 0, end: 2 }, append_whitespace: false},
]);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all the data from the tree
§Example
use reedline::{DefaultCompleter,Completer};
let mut completions = DefaultCompleter::default();
completions.insert(vec!["batman","robin","batmobile","batcave","robber"].iter().map(|s| s.to_string()).collect());
assert_eq!(completions.word_count(), 5);
assert_eq!(completions.size(), 24);
completions.clear();
assert_eq!(completions.size(), 1);
assert_eq!(completions.word_count(), 0);Sourcepub fn word_count(&self) -> u32
pub fn word_count(&self) -> u32
Returns a count of how many words that exist in the tree
§Example
use reedline::{DefaultCompleter,Completer};
let mut completions = DefaultCompleter::default();
completions.insert(vec!["batman","robin","batmobile","batcave","robber"].iter().map(|s| s.to_string()).collect());
assert_eq!(completions.word_count(), 5);Sourcepub fn size(&self) -> u32
pub fn size(&self) -> u32
Returns the size of the tree, the amount of nodes, not words
§Example
use reedline::{DefaultCompleter,Completer};
let mut completions = DefaultCompleter::default();
completions.insert(vec!["batman","robin","batmobile","batcave","robber"].iter().map(|s| s.to_string()).collect());
assert_eq!(completions.size(), 24);Sourcepub fn min_word_len(&self) -> usize
pub fn min_word_len(&self) -> usize
Returns the minimum word length to complete. This allows you
to pass full sentences to insert() and not worry about
pruning out small words like “a” or “to”, because they will be
ignored.
§Example
use reedline::{DefaultCompleter,Completer};
let mut completions = DefaultCompleter::default().set_min_word_len(4);
completions.insert(vec!["one","two","three","four","five"].iter().map(|s| s.to_string()).collect());
assert_eq!(completions.word_count(), 3);
let mut completions = DefaultCompleter::default().set_min_word_len(1);
completions.insert(vec!["one","two","three","four","five"].iter().map(|s| s.to_string()).collect());
assert_eq!(completions.word_count(), 5);Sourcepub fn set_min_word_len(self, len: usize) -> Self
pub fn set_min_word_len(self, len: usize) -> Self
Sets the minimum word length to complete on. Smaller words are
ignored. This only affects future calls to insert() -
changing this won’t start completing on smaller words that
were added in the past, nor will it exclude larger words
already inserted into the completion tree.
Trait Implementations§
Source§impl Clone for DefaultCompleter
impl Clone for DefaultCompleter
Source§fn clone(&self) -> DefaultCompleter
fn clone(&self) -> DefaultCompleter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Completer for DefaultCompleter
impl Completer for DefaultCompleter
Source§fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion>
fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion>
Returns a vector of completions and the position in which they must be replaced; based on the provided input.
§Arguments
lineThe line to completeposThe cursor position
§Example
use reedline::{DefaultCompleter,Completer,Span,Suggestion};
let mut completions = DefaultCompleter::default();
completions.insert(vec!["batman","robin","batmobile","batcave","robber"].iter().map(|s| s.to_string()).collect());
assert_eq!(
completions.complete("bat",3),
vec![
Suggestion {value: "batcave".into(), description: None, extra: None, span: Span { start: 0, end: 3 }, append_whitespace: false},
Suggestion {value: "batman".into(), description: None, extra: None, span: Span { start: 0, end: 3 }, append_whitespace: false},
Suggestion {value: "batmobile".into(), description: None, extra: None, span: Span { start: 0, end: 3 }, append_whitespace: false},
]);
assert_eq!(
completions.complete("to the bat",10),
vec![
Suggestion {value: "batcave".into(), description: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
Suggestion {value: "batman".into(), description: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
Suggestion {value: "batmobile".into(), description: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
]);Source§fn partial_complete(
&mut self,
line: &str,
pos: usize,
start: usize,
offset: usize,
) -> Vec<Suggestion>
fn partial_complete( &mut self, line: &str, pos: usize, start: usize, offset: usize, ) -> Vec<Suggestion>
Source§impl Debug for DefaultCompleter
impl Debug for DefaultCompleter
Auto Trait Implementations§
impl Freeze for DefaultCompleter
impl RefUnwindSafe for DefaultCompleter
impl Send for DefaultCompleter
impl Sync for DefaultCompleter
impl Unpin for DefaultCompleter
impl UnwindSafe for DefaultCompleter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more