pub struct Combobox<T: Searchable + Send + Sync + 'static> { /* private fields */ }Expand description
A fuzzy-searchable picker that filters items as the user types.
Combobox wraps a FuzzyMatcher and adds selection tracking with scroll offset for large result sets. Items must implement the Searchable trait.
Requires feature picker.
§Usage
use tui::{Combobox, Searchable};
#[derive(Clone)]
struct Tool { name: String }
impl Searchable for Tool {
fn search_text(&self) -> String { self.name.clone() }
}
let picker = Combobox::new(vec![
Tool { name: "read_file".into() },
Tool { name: "write_file".into() },
Tool { name: "list_dir".into() },
]);§Event handling
Combobox implements Component with Message = PickerMessage<T>. Use classify_key to map raw key events to PickerKey variants for custom handling outside the component.
Key messages:
PickerMessage::Confirm(T)— User selected an item (Enter).PickerMessage::Close— User dismissed the picker (Esc).PickerMessage::CharTyped(char)— A character was typed (updates the fuzzy query).PickerMessage::PopChar— Backspace pressed.PickerMessage::CloseAndPopChar/CloseWithChar(char)— Close and forward the key to the parent.
§Key methods
query()— The current search string.matches()— The filtered and ranked items.selected_index()— Index intomatches().selected_item()— The currently highlighted item.
§See also
Searchable— Trait items must implement for fuzzy matching.FuzzyMatcher— The underlying matching engine.PickerKey— Classified key event variants.
Implementations§
Source§impl<T: Searchable + Send + Sync + 'static> Combobox<T>
impl<T: Searchable + Send + Sync + 'static> Combobox<T>
pub fn new(items: Vec<T>) -> Self
pub fn from_matches(matches: Vec<T>) -> Self
pub fn query(&self) -> &str
pub fn matches(&self) -> &[T]
pub fn selected_index(&self) -> usize
pub fn set_max_visible(&mut self, max: usize)
pub fn set_match_sort(&mut self, sort: fn(&T, &T) -> Ordering)
pub fn is_empty(&self) -> bool
pub fn selected(&self) -> Option<&T>
pub fn push_query_char(&mut self, c: char)
pub fn pop_query_char(&mut self)
pub fn set_selected_index(&mut self, index: usize)
pub fn move_up(&mut self)
pub fn move_down(&mut self)
pub fn move_up_where(&mut self, predicate: impl Fn(&T) -> bool)
pub fn move_down_where(&mut self, predicate: impl Fn(&T) -> bool)
pub fn select_first_where(&mut self, predicate: impl Fn(&T) -> bool)
pub fn render_items( &self, context: &ViewContext, render_item: impl Fn(&T, bool, &ViewContext) -> Line, ) -> Vec<Line>
pub fn visible_matches_with_selection(&self) -> Vec<(&T, bool)>
Sourcepub fn handle_picker_event(
&mut self,
event: &Event,
) -> Option<Vec<PickerMessage<T>>>
pub fn handle_picker_event( &mut self, event: &Event, ) -> Option<Vec<PickerMessage<T>>>
Standard event dispatch for picker-style components.
Handles Escape, Up/Down, Enter (confirm), Char (query + whitespace-close),
Backspace, and BackspaceOnEmpty. Returns PickerMessage<T> for each action.
Auto Trait Implementations§
impl<T> Freeze for Combobox<T>
impl<T> !RefUnwindSafe for Combobox<T>
impl<T> Send for Combobox<T>
impl<T> Sync for Combobox<T>
impl<T> Unpin for Combobox<T>where
T: Unpin,
impl<T> UnsafeUnpin for Combobox<T>
impl<T> !UnwindSafe for Combobox<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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