TermUI.Widgets.TreeView (TermUI v0.2.0)
View SourceTreeView widget for displaying hierarchical data with expand/collapse.
TreeView renders a tree structure with indentation, supporting lazy loading for large trees, keyboard navigation, single/multi-selection, and search filtering.
Usage
TreeView.new(
nodes: [
TreeView.node(:root, "Root", children: [
TreeView.node(:child1, "Child 1"),
TreeView.node(:child2, "Child 2", children: [
TreeView.node(:grandchild, "Grandchild")
])
])
],
on_select: fn node -> handle_select(node) end,
on_expand: fn node -> load_children(node) end
)Node Structure
Nodes are maps with:
:id- Unique identifier (required):label- Display text (required):icon- Optional icon string:children- List of child nodes,:lazyfor on-demand loading, ornilfor leaf:disabled- Whether node is disabled:metadata- User-defined data
Keyboard Navigation
- Up/Down: Move cursor between visible nodes
- Left: Collapse node or move to parent
- Right: Expand node or move to first child
- Enter/Space: Toggle expand or select
- Home/End: Jump to first/last visible node
- PageUp/PageDown: Jump by page
- Ctrl+A: Select all (multi-select mode)
- Shift+Up/Down: Extend selection (multi-select mode)
- /: Start search filter
- Escape: Clear filter or deselect
Summary
Functions
Creates a branch node with children.
Clears the filter.
Clears the selection.
Collapses a node by ID.
Collapses all nodes.
Expands a node by ID.
Expands all nodes.
Marks a node as finished loading (clears loading state).
Gets the expanded node IDs.
Gets the currently focused node.
Gets the currently selected node IDs.
Creates a lazy-loading node.
Creates a leaf node (no children).
Creates new TreeView widget props.
Creates a tree node.
Updates the children of a node (for lazy loading).
Sets the filter programmatically.
Sets the selection programmatically.
Types
Functions
Creates a branch node with children.
Clears the filter.
Clears the selection.
Collapses a node by ID.
Collapses all nodes.
Expands a node by ID.
Expands all nodes.
Marks a node as finished loading (clears loading state).
Gets the expanded node IDs.
Gets the currently focused node.
Gets the currently selected node IDs.
Creates a lazy-loading node.
Creates a leaf node (no children).
Creates new TreeView widget props.
Options
:nodes- List of root nodes (required):on_select- Callback when node is selected:fn node -> ... end:on_expand- Callback when node is expanded:fn node -> children | :loading end:on_collapse- Callback when node is collapsed:fn node -> ... end:selection_mode-:single,:multi, or:none(default::single):show_root- Show root nodes (default: true):indent_size- Characters per indent level (default: 2):icons- Icon configuration map:initially_expanded- List of node IDs to expand initially:initially_selected- List of node IDs to select initially
Creates a tree node.
Options
:children- Child nodes,:lazyfor on-demand loading, or omit for leaf:icon- Custom icon string:disabled- Whether node is disabled (default: false):metadata- User-defined data map
Updates the children of a node (for lazy loading).
Sets the filter programmatically.
Sets the selection programmatically.