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>
impl<T> TreeSelect<T>
Sourcepub fn new<I, V>(prompt: impl Into<String>, nodes: I) -> TreeSelect<T>
pub fn new<I, V>(prompt: impl Into<String>, nodes: I) -> TreeSelect<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.
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.
Sourcepub fn crumbs(self, crumbs: Vec<String>) -> Self
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.
Sourcepub fn paths(self, paths: Vec<String>) -> Self
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.
Sourcepub fn paths_with(
self,
path: impl Fn(usize) -> String + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn fold_below(self, depth: usize) -> Self
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.
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 tree_keymap) on this tree only.
Sourcepub fn path_to(&self, index: usize) -> Vec<&str>
pub fn path_to(&self, index: usize) -> Vec<&str>
The names on the path to node index, from the root.
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.
Sourcepub fn set_hints(&mut self, hints: Option<String>)
pub fn set_hints(&mut self, hints: Option<String>)
The footer’s extra key hints (default ←→ fold).
Sourcepub fn collapsed(self, collapsed: bool) -> Self
pub fn collapsed(self, collapsed: bool) -> Self
Start with every node that has children collapsed (true) or
expanded.
pub fn preview(self, layout: PreviewLayout) -> Self
pub fn theme(self, theme: Theme) -> Self
Sourcepub fn default(self, index: usize) -> Self
pub fn default(self, index: usize) -> Self
The row returned without a terminal, and focused first.
Sourcepub fn actions(self, actions: Actions) -> Self
pub fn actions(self, actions: Actions) -> Self
Actions offered on every row, beside each row’s own.
The key that opens the action menu (default Ctrl+K).
Sourcepub fn with_mouse(self, on: bool) -> Self
pub fn with_mouse(self, on: bool) -> Self
Report the mouse: see Select::with_mouse.
pub fn items(&self) -> &[Item<T>]
Sourcepub fn set_icons(&mut self, icons: Vec<Option<Text>>)
pub fn set_icons(&mut self, icons: Vec<Option<Text>>)
An icon before each row’s label, by item index: see
Select::set_icons.
Sourcepub fn is_collapsed(&self, index: usize) -> bool
pub fn is_collapsed(&self, index: usize) -> bool
Whether node index is collapsed.
Sourcepub fn set_collapsed(&mut self, index: usize, collapsed: bool)
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>
impl<T: Clone> Component for TreeSelect<T>
type Output = T
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 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 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 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>
impl<T> Unpin for TreeSelect<T>
impl<T> UnsafeUnpin for TreeSelect<T>where
Select<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.