pub struct AutocompletePrompt<T: Clone + Send + Display> { /* private fields */ }
Expand description
Interactive prompt where the user chooses from a list of options
Shows a list of options. Use up/down to navigate
and enter to submit. Type anything to filter the list.
The default filter will simply check the choices start with the input’s .to_string().
The data vector can have a custom type but it must implement
std::fmt::Display
as well as std::clone::Clone
and std::marker::Send
.
§Examples
use prompt::{Prompt, autocomplete::{AutocompletePrompt}};
let data = vec!["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"];
let mut prompt = AutocompletePrompt::new("Choose a word", data);
match prompt.run().await {
Ok(Some(s)) => println!("Your choice is: {}", s),
Ok(None) => println!("Prompt was aborted!"),
Err(e) => println!("Some kind of crossterm error happened: {:?}", e),
}
Implementations§
Trait Implementations§
Source§impl<T: Clone + Send + Display> Prompt<T> for AutocompletePrompt<T>
impl<T: Clone + Send + Display> Prompt<T> for AutocompletePrompt<T>
Source§fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, ErrorKind>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, ErrorKind>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Runs the prompt
Stops either when the user selects an option, an error occurs, or the prompt is aborted by the user using CTRL+c, CTRL+z or ESC.
fn display(&mut self) -> Result<()>
fn handle_key_event(&mut self, event: KeyEvent)
Auto Trait Implementations§
impl<T> Freeze for AutocompletePrompt<T>
impl<T> RefUnwindSafe for AutocompletePrompt<T>where
T: RefUnwindSafe,
impl<T> Send for AutocompletePrompt<T>
impl<T> Sync for AutocompletePrompt<T>where
T: Sync,
impl<T> Unpin for AutocompletePrompt<T>where
T: Unpin,
impl<T> UnwindSafe for AutocompletePrompt<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more