pub struct Select<T> { /* private fields */ }Expand description
A fuzzy single choice among items. Enter returns the focused item’s value; Escape cancels.
Implementations§
Source§impl<T> Select<T>
impl<T> Select<T>
pub fn new<I, V>(prompt: impl Into<String>, items: I) -> Select<T>
pub fn preview(self, layout: PreviewLayout) -> Self
Sourcepub fn preview_height(self, rows: usize) -> Self
pub fn preview_height(self, rows: usize) -> Self
Rows the preview takes when it is below the list (default 10).
pub fn theme(self, theme: Theme) -> Self
Sourcepub fn repaint_every(self, interval: Duration) -> Self
pub fn repaint_every(self, interval: Duration) -> Self
Render again at least every interval, even with no key pressed:
for previews that fill in by themselves, such as a command’s output
computed on another thread. An unchanged view still writes nothing.
Sourcepub fn default(self, index: usize) -> Self
pub fn default(self, index: usize) -> Self
The item returned without a terminal when the policy asks for defaults, and focused first.
Sourcepub fn actions(self, actions: Actions) -> Self
pub fn actions(self, actions: Actions) -> Self
Actions offered on every item, beside each item’s own (#491): in the action menu, and on their keys.
The key that opens the action menu (default Ctrl+K).
Sourcepub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self
pub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self
Make keys do action (see select_keymap) on this select only;
no keys unbinds it.
Sourcepub fn with_mouse(self, on: bool) -> Self
pub fn with_mouse(self, on: bool) -> Self
Report the mouse (#476): a click focuses a row, a second click picks it, and the border beside a preview drags.
Sourcepub fn reload_on(
self,
key: Key,
source: impl FnMut() -> Vec<Item<T>> + Send + 'static,
) -> Self
pub fn reload_on( self, key: Key, source: impl FnMut() -> Vec<Item<T>> + Send + 'static, ) -> Self
Reload the items from source when key is pressed (#485), as
reload does: the query, the focused item and the
marks stay.
Sourcepub fn reload_from(self, feed: Receiver<Vec<Item<T>>>) -> Self
pub fn reload_from(self, feed: Receiver<Vec<Item<T>>>) -> Self
Take new items from feed whenever they arrive (#485): a watcher or
a command on another thread sends the whole list again, and the
select reloads it, keeping the query, the focused
item and the marks. The select looks every 100 ms.
Sourcepub fn split(self, columns: usize) -> Self
pub fn split(self, columns: usize) -> Self
The list’s width beside a preview, in columns: where the border is until it is dragged.
Sourcepub fn action(&self) -> Option<&str>
pub fn action(&self) -> Option<&str>
The id of the Action that picked the item, from its key or the
action menu, if one did.
pub fn items(&self) -> &[Item<T>]
Sourcepub fn split_width(&self) -> Option<usize>
pub fn split_width(&self) -> Option<usize>
The list’s width beside a preview, once dragged.
Sourcepub fn filter(&self) -> &FilterState
pub fn filter(&self) -> &FilterState
The query and what matches it.
The action menu, while it is open.
Sourcepub fn select_keymap(&self) -> &Keymap
pub fn select_keymap(&self) -> &Keymap
The keys, with any rebinding.
Sourcepub fn is_multi(&self) -> bool
pub fn is_multi(&self) -> bool
Whether this is the list of a MultiSelect.
Sourcepub fn set_kind(&mut self, kind: TargetKind)
pub fn set_kind(&mut self, kind: TargetKind)
What an action is done to: an item, a row, a node, a file.
Sourcepub fn set_values(&mut self, values: Vec<String>)
pub fn set_values(&mut self, values: Vec<String>)
Each item’s identity for an action (ActionTarget::value), by
index; the label where missing.
Sourcepub fn set_heading(&mut self, heading: Option<Vec<Segment>>)
pub fn set_heading(&mut self, heading: Option<Vec<Segment>>)
A line above the list, under the question: a table’s headings.
Sourcepub fn set_prefixes(&mut self, prefixes: Vec<String>, plain: bool)
pub fn set_prefixes(&mut self, prefixes: Vec<String>, plain: bool)
Text before each label, by index, not searched: a tree’s guides, an
emoji. Dimmed, unless plain. Call refilter
after.
Sourcepub fn set_icons(&mut self, icons: Vec<Option<Text>>)
pub fn set_icons(&mut self, icons: Vec<Option<Text>>)
An icon before each label, by index, after its prefix: one line of
text (see kit::icon), its styles and metadata
kept, so a micro asset’s placeholder cells stay tagged for the
painter’s graphics. None leaves an item without one.
Items left out while nothing is typed, by index: a collapsed node’s
children. Call refilter after.
Sourcepub fn set_steady(&mut self, steady: bool)
pub fn set_steady(&mut self, steady: bool)
Always take the full height, however few items there are: for lists that change under the user, such as a directory’s entries.
Sourcepub fn reload(&mut self, items: Vec<Item<T>>)
pub fn reload(&mut self, items: Vec<Item<T>>)
Replace the items and keep the user’s place (#485): the query stays
and is matched against the new items, the focused item stays
focused if it is still there (matched by label), and so do the
marks. Per-item settings (values, prefixes, what is hidden) are
cleared, as with replace_items; a view that
sets them sets them again.
Sourcepub fn set_status(&mut self, status: Option<String>)
pub fn set_status(&mut self, status: Option<String>)
Show status in place of the footer until the next key: what an
action just did.
Sourcepub fn set_tree(&mut self, parents: Option<Vec<Option<usize>>>)
pub fn set_tree(&mut self, parents: Option<Vec<Option<usize>>>)
Filter as a tree (#428; see FilterState::set_tree): matches keep
their ancestors, dimmed, and the cursor goes to the best match.
Sourcepub fn tick_interval(&self) -> Option<Duration>
pub fn tick_interval(&self) -> Option<Duration>
How often to tick: the repaint interval, and often enough to take fed items.
Sourcepub fn replace_items(&mut self, items: Vec<Item<T>>)
pub fn replace_items(&mut self, items: Vec<Item<T>>)
Replace the items, keeping the settings; the query is cleared.
Whether the action menu is open.
Sourcepub fn query_text(&self) -> &str
pub fn query_text(&self) -> &str
What is typed.
Sourcepub fn set_answer(&mut self, answer: Option<String>)
pub fn set_answer(&mut self, answer: Option<String>)
Show answer in place of the list (None: cancelled), as a
finished select does.
Sourcepub fn focus_item(&mut self, index: usize)
pub fn focus_item(&mut self, index: usize)
Focus item index if it is listed.
Sourcepub fn target(&self, index: usize) -> ActionTarget
pub fn target(&self, index: usize) -> ActionTarget
The target an action on item index is done to.
Sourcepub fn actions_for(&self, index: usize) -> Vec<Action>
pub fn actions_for(&self, index: usize) -> Vec<Action>
Every action for item index: its own, then the view’s that apply.
Sourcepub fn refilter(&mut self)
pub fn refilter(&mut self)
Match the items against the query again, after the items, their prefixes or what is hidden changed.
Sourcepub fn event(
&mut self,
event: &Event,
context: &Context<'_>,
) -> Option<Flow<Vec<usize>>>
pub fn event( &mut self, event: &Event, context: &Context<'_>, ) -> Option<Flow<Vec<usize>>>
Handle an event as the select does, for a component built round
one: Some(Flow::Done) finishes with item indices (the view then
collapses to the answer), Some(Flow::Cancel) cancels,
Some(Flow::Ignored) means the event was not the select’s, and
None carries on.
Sourcepub fn list_lines(&self, width: usize) -> Vec<Vec<Segment>>
pub fn list_lines(&self, width: usize) -> Vec<Vec<Segment>>
The list’s rows at width: the matches shown, or “no matches”, kept
at a steady height.
The footer: counts and key hints.
Sourcepub fn visible_keymap(&self) -> Keymap
pub fn visible_keymap(&self) -> Keymap
The keys that apply now: no marking for a single choice, and the action menu’s while it is open.
Trait Implementations§
Source§impl<T: Clone> Component for Select<T>
impl<T: Clone> Component for Select<T>
type Output = T
Source§fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<T>
fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<T>
Outcome::Interrupted.Source§fn tick(&self) -> Option<Duration>
fn tick(&self) -> Option<Duration>
Event::Tick, for a spinner or a
countdown. None (the default): never.Source§fn mouse(&self) -> bool
fn mouse(&self) -> bool
run then enables mouse reporting
for the session.Source§fn keymap(&self) -> Keymap
fn keymap(&self) -> Keymap
keymap). A container’s include its focused
child’s, before its own. The default declares none.Source§fn default_value(&self) -> Option<T>
fn default_value(&self) -> Option<T>
None: there is none.Source§fn prompt(&mut self, io: &mut dyn LineIo) -> Result<Option<T>, NotInteractive>
fn prompt(&mut self, io: &mut dyn LineIo) -> Result<Option<T>, NotInteractive>
Source§fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>
fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>
Done or Cancel finishes the component
without waiting for an event. The default does nothing.Source§fn focusable(&self) -> bool
fn focusable(&self) -> bool
Source§fn focus_step(&mut self, forward: bool) -> bool
fn focus_step(&mut self, forward: bool) -> bool
forward) or previous focus stop inside
this component, for Tab and Shift+Tab. false when there is none
after the current one, so the container moves on to its next
child. The default, for a component that is one stop: false.Auto Trait Implementations§
impl<T> !Freeze for Select<T>
impl<T> !RefUnwindSafe for Select<T>
impl<T> !Sync for Select<T>
impl<T> !UnwindSafe for Select<T>
impl<T> Send for Select<T>
impl<T> Unpin for Select<T>
impl<T> UnsafeUnpin for Select<T>where
Vec<Item<T>>: UnsafeUnpin,
Option<Box<dyn FnMut() -> Vec<Item<T>> + Send>>: UnsafeUnpin,
Option<Receiver<Vec<Item<T>>>>: UnsafeUnpin,
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
Source§impl<C> ComponentExt for Cwhere
C: Component,
impl<C> ComponentExt for Cwhere
C: Component,
Source§fn map<'a, M>(
self,
done: impl FnMut(Self::Output) -> Flow<M> + 'a,
) -> Map<'a, Self, M>where
Self: 'a,
fn map<'a, M>(
self,
done: impl FnMut(Self::Output) -> Flow<M> + 'a,
) -> Map<'a, Self, M>where
Self: 'a,
M’s flow: Flow::Done(m) to
finish the whole composition with m, Flow::Continue to carry on
(the component stays, showing its answer, and focus moves past it).
Cancelling cancels the composition unless
on_cancel says otherwise.