[][src]Struct prompts::autocomplete::AutocompletePrompt

pub struct AutocompletePrompt<T: Clone + Send + Display> { /* fields omitted */ }

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]

Returns a AutocompletePrompt ready to be run

Arguments

  • message - The message to display to the user before the prompt
  • choices - 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]

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.

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.