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)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
source

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

Examples found in repository?
examples/demo.rs (line 10)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
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_prompt(self, prompt: impl Into<String>) -> Self

Examples found in repository?
examples/demo.rs (line 9)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
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_initial_selection(self, initial_selection: u32) -> Self

Examples found in repository?
examples/demo.rs (line 12)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
source

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

Examples found in repository?
examples/demo.rs (line 11)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
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_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)
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let items = vec!["Hello there", "General Kenobi", "You are a bold one"];

    let item = FuzzySelect::new()
        .with_prompt("Select your destiny:")
        .with_options(items)
        .with_query("o")
        .with_initial_selection(2)
        .select()
        .expect("Failed to create FuzzySelect");

    println!("You have chosen: {item:?}");
}
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 copy 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> 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> 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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,

§

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>,

§

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>,

§

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.