Skip to main content

TreeSelect

Struct TreeSelect 

Source
pub struct TreeSelect<T> { /* private fields */ }
Expand description

Pick a node of a tree. Nodes are given in order, each with its depth (0 for a root); Right expands the focused node and Left collapses it, or moves to its parent.

Typing searches every node, collapsed or not, and filters as a tree (#428): each match keeps its ancestors, dimmed, so you see where it is, and the cursor goes to the best match. With breadcrumbs on, a line under the question shows the path to the focused node (#464). Ctrl+Y copies that path (the node’s ActionTarget::value) to the terminal’s clipboard.

Implementations§

Source§

impl<T> TreeSelect<T>

Source

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

A tree of nodes, in order, each with its depth.

Building it is linear in the number of nodes, and so is what it keeps: each node’s path (the labels joined by /) is worked out when it is asked for, and its guides when its row is drawn.

Source

pub fn breadcrumbs(self, on: bool) -> Self

Show the path to the focused node on a line under the question (#464): root › parent › node, cut from the left when it is too wide.

Source

pub fn crumbs(self, crumbs: Vec<String>) -> Self

Each node’s name in the breadcrumbs, by index, in place of its label: a key rather than key: value, say.

Source

pub fn paths(self, paths: Vec<String>) -> Self

What Ctrl+Y copies and actions see as each node’s value, by index, in place of the labels joined by /: a JSON path, say. Nodes past the end of paths keep the joined labels.

Source

pub fn paths_with( self, path: impl Fn(usize) -> String + Send + Sync + 'static, ) -> Self

Like paths, with each node’s value worked out from its index when it is asked for (the focused node’s, on Ctrl+Y or an action), so a large tree keeps no string per node.

Source

pub fn fold_below(self, depth: usize) -> Self

Collapse every node at depth or deeper that has children, and expand the rest: fold_below(1) shows the roots’ children only.

Source

pub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self

Make keys do action (see tree_keymap) on this tree only.

Source

pub fn parents(&self) -> &[Option<usize>]

Each node’s parent, by index.

Source

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

The focused node’s index.

Source

pub fn path_to(&self, index: usize) -> Vec<&str>

The names on the path to node index, from the root.

Source

pub fn set_status(&mut self, status: Option<String>)

Show status in place of the footer until the next key.

Source

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

The footer’s extra key hints (default ←→ fold).

Source

pub fn collapsed(self, collapsed: bool) -> Self

Start with every node that has children collapsed (true) or expanded.

Source

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

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

Source

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

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 default(self, index: usize) -> Self

The row returned without a terminal, and focused first.

Source

pub fn actions(self, actions: Actions) -> Self

Actions offered on every row, beside each row’s own.

Source

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

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

Source

pub fn with_mouse(self, on: bool) -> Self

Report the mouse: see Select::with_mouse.

Source

pub fn action(&self) -> Option<&str>

The id of the action that picked the row, if one did.

Source

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

Source

pub fn select(&self) -> &Select<T>

The underlying list.

Source

pub fn set_icons(&mut self, icons: Vec<Option<Text>>)

An icon before each row’s label, by item index: see Select::set_icons.

Source

pub fn is_collapsed(&self, index: usize) -> bool

Whether node index is collapsed.

Source

pub fn set_collapsed(&mut self, index: usize, collapsed: bool)

Collapse (true) or expand node index.

Trait Implementations§

Source§

impl<T: Clone> Component for TreeSelect<T>

Source§

type Output = T

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 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 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 TreeSelect<T>

§

impl<T> !RefUnwindSafe for TreeSelect<T>

§

impl<T> !Sync for TreeSelect<T>

§

impl<T> !UnwindSafe for TreeSelect<T>

§

impl<T> Send for TreeSelect<T>
where Select<T>: Send,

§

impl<T> Unpin for TreeSelect<T>
where Select<T>: Unpin,

§

impl<T> UnsafeUnpin for TreeSelect<T>
where Select<T>: UnsafeUnpin,

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.