Struct fuzzy_select::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>
impl<T> FuzzySelect<T>
sourcepub fn new() -> Self
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:?}");
}sourcepub fn with_options(self, options: Vec<T>) -> Self
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:?}");
}pub fn with_options_from_iter( self, options: impl IntoIterator<Item = T> ) -> Self
pub fn with_options_from_slice(self, options: &[T]) -> Selfwhere
T: Clone,
pub fn add_option(self, option: T) -> Self
pub fn add_options(self, options: impl IntoIterator<Item = T>) -> Self
sourcepub fn with_prompt(self, prompt: impl Into<String>) -> Self
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:?}");
}pub fn without_prompt(self) -> Self
pub fn set_prompt<P: Into<String>>(self, prompt: impl Into<Option<P>>) -> Self
sourcepub fn with_initial_selection(self, initial_selection: u32) -> Self
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:?}");
}sourcepub fn with_query(self, query: impl Into<String>) -> Self
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:?}");
}pub fn without_query(self) -> Self
pub fn set_query<Q: Into<String>>(self, query: impl Into<Option<Q>>) -> Self
pub fn without_highlight(self) -> Self
pub fn set_highlight(self, highlight: bool) -> Self
pub fn with_page_size(self, page_size: u16) -> Self
pub fn with_default_page_size(self) -> Self
pub fn with_color(self, color: bool) -> Self
pub fn with_default_color(self) -> Self
pub fn set_color(self, color: impl Into<Option<bool>>) -> Self
pub fn with_theme(self, theme: Theme) -> Self
pub fn with_default_theme(self) -> Self
pub fn without_alternate_screen(self) -> Self
pub fn with_alternate_screen(self) -> Self
pub fn set_alternate_screen(self, alternate_screen: bool) -> Self
sourcepub fn select(self) -> Result<T>where
T: Select,
pub fn select(self) -> Result<T>where
T: Select,
Runs the fuzzy select prompt and returns the selected item.
Errors
Error::NoOptionsif there are no options to select from. Need to call one of the*option*methods before calling this.Error::Cancelledif the user cancelled the selection (e.g. by hitting Ctrl-C or Esc).Error::InvalidSelectionif the default selection index is out of bounds based off the provided options.Error::NonInteractiveif the terminal is not in interactive mode. This is the case if the terminal is not a tty.Error::IoErrorif 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:?}");
}sourcepub fn select_opt(self) -> Result<Option<T>>where
T: Select,
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::NonInteractiveif the terminal is not in interactive mode. This is the case if the terminal is not a tty.Error::IoErrorif there was an error interacting with interacting with terminal in general.
Trait Implementations§
source§impl<T: Clone> Clone for FuzzySelect<T>
impl<T: Clone> Clone for FuzzySelect<T>
source§fn clone(&self) -> FuzzySelect<T>
fn clone(&self) -> FuzzySelect<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<T: Debug> Debug for FuzzySelect<T>
impl<T: Debug> Debug for FuzzySelect<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more