Struct AutocompletePrompt

Source
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§

Source§

impl<T: Clone + Send + Display> AutocompletePrompt<T>

Source

pub fn new<S>(message: S, choices: Vec<T>) -> AutocompletePrompt<T>
where S: Into<String>,

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§

Source§

impl<T: Debug + Clone + Send + Display> Debug for AutocompletePrompt<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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,

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.

Source§

fn display(&mut self) -> Result<()>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.