Struct FuzzySelect

Source
pub struct FuzzySelect<T> { /* private fields */ }
Expand description

A fuzzy select prompt. See the module level documentation for more information.

Implementations§

Source§

impl<T> FuzzySelect<T>

Source

pub fn new() -> Self

Examples found in repository?
examples/demo.rs (line 8)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn with_prompt(self, prompt: impl Into<String>) -> Self

Examples found in repository?
examples/demo.rs (line 9)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn without_prompt(self) -> Self

Source

pub fn set_prompt<P: Into<String>>(self, prompt: impl Into<Option<P>>) -> Self

Source

pub fn with_options(self, options: Vec<T>) -> Self

Examples found in repository?
examples/demo.rs (line 10)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn with_options_from_iter( self, options: impl IntoIterator<Item = T>, ) -> Self

Source

pub fn with_options_from_slice(self, options: &[T]) -> Self
where T: Clone,

Source

pub fn add_option(self, option: T) -> Self

Source

pub fn add_options(self, options: impl IntoIterator<Item = T>) -> Self

Source

pub fn with_initial_selection(self, initial_selection: u32) -> Self

Examples found in repository?
examples/demo.rs (line 12)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn with_query(self, query: impl Into<String>) -> Self

Examples found in repository?
examples/demo.rs (line 11)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn without_query(self) -> Self

Source

pub fn set_query<Q: Into<String>>(self, query: impl Into<Option<Q>>) -> Self

Source

pub fn with_filter(self) -> Self

Source

pub fn without_filter(self) -> Self

Source

pub fn set_filter(self, filter: bool) -> Self

Source

pub fn with_select1(self) -> Self

Source

pub fn without_select1(self) -> Self

Source

pub fn set_select1(self, select1: bool) -> Self

Source

pub fn without_highlight(self) -> Self

Source

pub fn set_highlight(self, highlight: bool) -> Self

Source

pub fn with_page_size(self, page_size: u16) -> Self

Source

pub fn with_default_page_size(self) -> Self

Source

pub fn with_color(self, color: bool) -> Self

Source

pub fn with_default_color(self) -> Self

Source

pub fn set_color(self, color: impl Into<Option<bool>>) -> Self

Source

pub fn with_theme(self, theme: Theme) -> Self

Source

pub fn with_default_theme(self) -> Self

Source

pub fn without_alternate_screen(self) -> Self

Source

pub fn with_alternate_screen(self) -> Self

Source

pub fn set_alternate_screen(self, alternate_screen: bool) -> Self

Source

pub fn select(self) -> Result<T>
where T: Select,

Runs the fuzzy select prompt and returns the selected item.

§Errors
  • Error::NoOptions if there are no options to select from. Need to call one of the *option* methods before calling this.
  • Error::Cancelled if the user cancelled the selection (e.g. by hitting Ctrl-C or Esc).
  • Error::InvalidSelection if the default selection index is out of bounds based off the provided options.
  • Error::NonInteractive if the terminal is not in interactive mode. This is the case if the terminal is not a tty.
  • Error::IoError if there was an error interacting with interacting with terminal in general.
Examples found in repository?
examples/demo.rs (line 13)
5fn main() {
6    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];
7
8    let item = FuzzySelect::new()
9        .with_prompt("Select your destiny:")
10        .with_options(items)
11        .with_query("o")
12        .with_initial_selection(2)
13        .select()
14        .expect("Failed to create FuzzySelect");
15
16    println!("You have chosen: {item:?}");
17}
Source

pub fn select_opt(self) -> Result<Option<T>>
where T: Select,

Runs the fuzzy select prompt and returns the selected item or None if no selection was made.

§Errors
  • Error::NonInteractive if the terminal is not in interactive mode. This is the case if the terminal is not a tty.
  • Error::IoError if there was an error interacting with interacting with terminal in general.

Trait Implementations§

Source§

impl<T: Clone> Clone for FuzzySelect<T>

Source§

fn clone(&self) -> FuzzySelect<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for FuzzySelect<T>

Source§

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

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

impl<T> Default for FuzzySelect<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FuzzySelect<T>

§

impl<T> RefUnwindSafe for FuzzySelect<T>
where T: RefUnwindSafe,

§

impl<T> Send for FuzzySelect<T>
where T: Send,

§

impl<T> Sync for FuzzySelect<T>
where T: Sync,

§

impl<T> Unpin for FuzzySelect<T>
where T: Unpin,

§

impl<T> UnwindSafe for FuzzySelect<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.