Skip to main content

FuzzySelect

Struct FuzzySelect 

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

An inline fuzzy-select prompt.

§Examples

use sparcli::{FuzzySelect, Outcome};

if let Outcome::Submitted(index) =
    FuzzySelect::new("Find a fruit:").options(["apple", "banana"]).run()?
{
    println!("chose option {index}");
}

Implementations§

Source§

impl FuzzySelect

Source

pub fn new(prompt: impl Into<String>) -> Self

Creates a fuzzy prompt with the given label.

Examples found in repository?
examples/prompts.rs (line 102)
101fn pick_fruit() -> sparcli::Result<Outcome<usize>> {
102    FuzzySelect::new("Find a fruit:")
103        .options(["apple", "apricot", "banana", "cherry", "grape"])
104        .run()
105}
Source

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

Pre-fills the search query.

Source

pub fn shortcuts<I>(self, shortcuts: I) -> Self
where I: IntoIterator<Item = Shortcut>,

Registers shortcuts shown in a footer hint.

Pressing a bound key ends the prompt with Outcome::Shortcut. Use modified keys (e.g. Ctrl-…) so they do not collide with typing.

Source

pub fn options<I, S>(self, options: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Adds options from any string iterator.

Examples found in repository?
examples/prompts.rs (line 103)
101fn pick_fruit() -> sparcli::Result<Outcome<usize>> {
102    FuzzySelect::new("Find a fruit:")
103        .options(["apple", "apricot", "banana", "cherry", "grape"])
104        .run()
105}
Source

pub fn multi(self) -> Self

Enables multi-selection with checkboxes.

Source

pub fn max_visible(self, rows: usize) -> Self

Sets the maximum number of visible result rows.

Source

pub fn run(self) -> Result<Outcome<usize>>

Runs a single-select fuzzy prompt, returning the chosen index.

§Errors

Returns SparcliError::NoTerminal without an interactive terminal, or SparcliError::Io on a terminal failure.

Examples found in repository?
examples/prompts.rs (line 104)
101fn pick_fruit() -> sparcli::Result<Outcome<usize>> {
102    FuzzySelect::new("Find a fruit:")
103        .options(["apple", "apricot", "banana", "cherry", "grape"])
104        .run()
105}
Source

pub fn run_multi(self) -> Result<Outcome<Vec<usize>>>

Runs a multi-select fuzzy prompt, returning all checked indices.

§Errors

Returns SparcliError::NoTerminal without an interactive terminal, or SparcliError::Io on a terminal failure.

Source

pub fn frame(&self) -> Rendered

Renders the prompt’s static frame without running it (for previews and README screenshots).

Auto Trait Implementations§

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.