Skip to main content

Select

Struct Select 

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

Source

pub fn new<I, V>(prompt: impl Into<String>, items: I) -> Select<T>
where I: IntoIterator<Item = V>, V: Into<Item<T>>,

Source

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

Show at most rows items at once (default 10).

Source

pub fn preview(self, layout: PreviewLayout) -> Self

Source

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

Rows the preview takes when it is below the list (default 10).

Source

pub fn theme(self, theme: Theme) -> Self

Source

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

Start with this filter text.

Source

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.

Source

pub fn default(self, index: usize) -> Self

The item returned without a terminal when the policy asks for defaults, and focused first.

Source

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.

Source

pub fn menu_key(self, key: Key) -> Self

The key that opens the action menu (default Ctrl+K).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn split(self, columns: usize) -> Self

The list’s width beside a preview, in columns: where the border is until it is dragged.

Source

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.

Source

pub fn items(&self) -> &[Item<T>]

Source

pub fn focused(&self) -> Option<usize>

The focused item’s index, if any item matches.

Source

pub fn split_width(&self) -> Option<usize>

The list’s width beside a preview, once dragged.

Source

pub fn filter(&self) -> &FilterState

The query and what matches it.

Source

pub fn list(&self) -> &ListState

The cursor, the scroll and the marks.

Source

pub fn divider(&self) -> &Divider

The border beside the preview.

Source

pub fn menu(&self) -> Option<&ActionMenu>

The action menu, while it is open.

Source

pub fn select_keymap(&self) -> &Keymap

The keys, with any rebinding.

Source

pub fn is_multi(&self) -> bool

Whether this is the list of a MultiSelect.

Source

pub fn set_kind(&mut self, kind: TargetKind)

What an action is done to: an item, a row, a node, a file.

Source

pub fn set_values(&mut self, values: Vec<String>)

Each item’s identity for an action (ActionTarget::value), by index; the label where missing.

Source

pub fn set_heading(&mut self, heading: Option<Vec<Segment>>)

A line above the list, under the question: a table’s headings.

Source

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.

Source

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.

Source

pub fn set_hidden(&mut self, hidden: Vec<bool>)

Items left out while nothing is typed, by index: a collapsed node’s children. Call refilter after.

Source

pub fn set_hints(&mut self, hints: Option<String>)

A line of extra key hints for the footer.

Source

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.

Source

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.

Source

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.

Source

pub fn status(&self) -> Option<&[Segment]>

The status line, if one is showing.

Source

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.

Source

pub fn tick_interval(&self) -> Option<Duration>

How often to tick: the repaint interval, and often enough to take fed items.

Source

pub fn replace_items(&mut self, items: Vec<Item<T>>)

Replace the items, keeping the settings; the query is cleared.

Source

pub fn menu_open(&self) -> bool

Whether the action menu is open.

Source

pub fn query_text(&self) -> &str

What is typed.

Source

pub fn set_answer(&mut self, answer: Option<String>)

Show answer in place of the list (None: cancelled), as a finished select does.

Source

pub fn reopen(&mut self)

Carry on after an Enter that did not finish (a directory opened).

Source

pub fn focus_item(&mut self, index: usize)

Focus item index if it is listed.

Source

pub fn target(&self, index: usize) -> ActionTarget

The target an action on item index is done to.

Source

pub fn actions_for(&self, index: usize) -> Vec<Action>

Every action for item index: its own, then the view’s that apply.

Source

pub fn refilter(&mut self)

Match the items against the query again, after the items, their prefixes or what is hidden changed.

Source

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.

Source

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.

Source

pub fn footer(&self, width: usize) -> Vec<Segment>

The footer: counts and key hints.

Source

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>

Source§

type Output = T

Source§

fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<T>

Handle one event. Ctrl+C never arrives here: the event loop ends the component with Outcome::Interrupted.
Source§

fn render(&self, context: &Context<'_>) -> View

Render the current state.
Source§

fn tick(&self) -> Option<Duration>

How often the component wants Event::Tick, for a spinner or a countdown. None (the default): never.
Source§

fn mouse(&self) -> bool

Whether the component wants mouse events (#476): clicks, drags and the wheel. Off by default, since reporting the mouse takes text selection away from the terminal; a component turns it on when its caller opts in, and run then enables mouse reporting for the session.
Source§

fn keymap(&self) -> Keymap

The bindings this component has right now, for a help overlay, a shortcut list or status-bar hints to read (see keymap). A container’s include its focused child’s, before its own. The default declares none.
Source§

fn default_value(&self) -> Option<T>

The value to return when the terminal is not interactive and the policy asks for defaults. None: there is none.
Source§

fn prompt(&mut self, io: &mut dyn LineIo) -> Result<Option<T>, NotInteractive>

Ask for the value line by line, for when the terminal is not interactive and the policy asks for a prompt. The default says the component has no line-based form. Read more
Source§

fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>

Called once, before the component is first painted, with the terminal’s size: for work that needs it, such as rendering content at the width. Returning Done or Cancel finishes the component without waiting for an event. The default does nothing.
Source§

fn focusable(&self) -> bool

Whether the component takes focus in a container: Tab stops on it and keys go to it. The default: yes. A label, or a component that has finished, says no.
Source§

fn focus_step(&mut self, forward: bool) -> bool

Move focus to the next (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.
Source§

fn focus_enter(&mut self, forward: bool) -> bool

Take focus from outside: at the first stop inside when forward, at the last otherwise. false when nothing in it can take focus. The default: whether the component is focusable.

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>
where Vec<Item<T>>: Send, Option<Box<dyn FnMut() -> Vec<Item<T>> + Send>>: Send, Option<Receiver<Vec<Item<T>>>>: Send,

§

impl<T> Unpin for Select<T>
where Vec<Item<T>>: Unpin, Option<Box<dyn FnMut() -> Vec<Item<T>> + Send>>: Unpin, Option<Receiver<Vec<Item<T>>>>: Unpin,

§

impl<T> UnsafeUnpin for Select<T>

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<C> ComponentExt for C
where C: Component,

Source§

fn map<'a, M>( self, done: impl FnMut(Self::Output) -> Flow<M> + 'a, ) -> Map<'a, Self, M>
where Self: 'a,

Turn this component’s answer into 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.
Source§

fn with_overlays<'a>(self) -> Overlays<'a, Self::Output>
where Self: 'a, Self::Output: 'a,

Wrap this component in Overlays: a command palette, help and a shortcut sheet read from its keymap, and room for a status bar and breadcrumbs.
Source§

fn boxed<'a>(self) -> Child<'a, Self::Output>
where Self: 'a,

Box this component as a Child.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.