[−][src]Struct prompts::autocomplete::AutocompletePrompt
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), }
Methods
impl<T: Clone + Send + Display> AutocompletePrompt<T>
[src]
pub fn new<S>(message: S, choices: Vec<T>) -> AutocompletePrompt<T> where
S: Into<String>,
[src]
S: Into<String>,
Returns a AutocompletePrompt ready to be run
Arguments
message
- The message to display to the user before the promptchoices
- A vector of options that the user can choose from
Trait Implementations
impl<T: Debug + Clone + Send + Display> Debug for AutocompletePrompt<T>
[src]
impl<T: Clone + Send + Display> Prompt<T> for AutocompletePrompt<T>
[src]
fn run<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Option<T>, ErrorKind>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Option<T>, ErrorKind>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: '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<()>
[src]
fn handle_key_event(&mut self, event: KeyEvent)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for AutocompletePrompt<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for AutocompletePrompt<T>
impl<T> Sync for AutocompletePrompt<T> where
T: Sync,
T: Sync,
impl<T> Unpin for AutocompletePrompt<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for AutocompletePrompt<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,