Documentation
¶
Overview ¶
Package tree provides a hierarchical list component for Bubble Tea applications, extending the core functionalities of the list component with tree-specific features like node expansion, indentation, and parent-child relationships.
Index ¶
- func FormatTreeItemContent(item core.Data[any], index int, depth int, hasChildren, isExpanded bool, ...) string
- func TreeEnumerator(item core.Data[any], index int, ctx core.RenderContext) stringdeprecated
- func TreeExpandedEnumerator(item core.Data[any], index int, ctx core.RenderContext) stringdeprecated
- func TreeMinimalEnumerator(item core.Data[any], index int, ctx core.RenderContext) stringdeprecated
- type FlatTreeItem
- type TreeBackgroundComponent
- type TreeBackgroundConfig
- type TreeBackgroundMode
- type TreeComponentContext
- type TreeComponentRenderer
- func (r *TreeComponentRenderer) DisableComponent(componentType TreeComponentType)
- func (r *TreeComponentRenderer) EnableComponent(componentType TreeComponentType)
- func (r *TreeComponentRenderer) GetComponent(componentType TreeComponentType) TreeRenderComponent
- func (r *TreeComponentRenderer) Render(item core.Data[any], index int, depth int, hasChildren, isExpanded bool, ...) string
- func (r *TreeComponentRenderer) SetComponentOrder(order []TreeComponentType)
- func (r *TreeComponentRenderer) UpdateConfig(config TreeRenderConfig)
- type TreeComponentType
- type TreeConfig
- type TreeContentComponent
- type TreeContentConfig
- type TreeCursorComponent
- type TreeCursorConfig
- type TreeData
- type TreeDataSource
- type TreeEnumeratorAlignment
- type TreeEnumeratorComponent
- type TreeEnumeratorConfig
- type TreeEnumeratorFunc
- type TreeIndentationComponent
- type TreeIndentationConfig
- type TreeItemFormatter
- type TreeList
- func (tl *TreeList[T]) Blur()
- func (tl *TreeList[T]) CollapseAll() tea.Cmd
- func (tl *TreeList[T]) CollapseCurrentSubtree() tea.Cmd
- func (tl *TreeList[T]) CollapseNode(id string) tea.Cmd
- func (tl *TreeList[T]) CollapseSubtree(id string) tea.Cmd
- func (tl *TreeList[T]) ExpandAll() tea.Cmd
- func (tl *TreeList[T]) ExpandCurrentSubtree() tea.Cmd
- func (tl *TreeList[T]) ExpandNode(id string) tea.Cmd
- func (tl *TreeList[T]) ExpandSubtree(id string) tea.Cmd
- func (tl *TreeList[T]) Focus() tea.Cmd
- func (tl *TreeList[T]) GetAutoExpand() bool
- func (tl *TreeList[T]) GetCascadingSelection() bool
- func (tl *TreeList[T]) GetCurrentNodeID() string
- func (tl *TreeList[T]) GetExpandOnSelect() bool
- func (tl *TreeList[T]) GetFullyExpandedItemCount() int
- func (tl *TreeList[T]) GetRenderConfig() TreeRenderConfig
- func (tl *TreeList[T]) GetSelectionCount() int
- func (tl *TreeList[T]) GetState() core.ViewportState
- func (tl *TreeList[T]) Init() tea.Cmd
- func (tl *TreeList[T]) IsFocused() bool
- func (tl *TreeList[T]) JumpToIndexExpandingParents(index int) tea.Cmd
- func (tl *TreeList[T]) SetAutoExpand(enabled bool)
- func (tl *TreeList[T]) SetCascadingSelection(enabled bool)
- func (tl *TreeList[T]) SetExpandOnSelect(enabled bool)
- func (tl *TreeList[T]) SetRenderConfig(config TreeRenderConfig)
- func (tl *TreeList[T]) SetTreeEnumerator()
- func (tl *TreeList[T]) SetTreeExpandedEnumerator()
- func (tl *TreeList[T]) SetTreeMinimalEnumerator()
- func (tl *TreeList[T]) ToggleCurrentNode() tea.Cmd
- func (tl *TreeList[T]) ToggleNode(id string) tea.Cmd
- func (tl *TreeList[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (tl *TreeList[T]) View() string
- type TreePostSpacingComponent
- type TreePreSpacingComponent
- type TreeRenderComponent
- type TreeRenderConfig
- func BackgroundStyledTreeConfig(style lipgloss.Style, mode TreeBackgroundMode) TreeRenderConfig
- func DefaultTreeRenderConfig() TreeRenderConfig
- func EnumeratedTreeConfig(enumerator TreeEnumeratorFunc) TreeRenderConfig
- func MinimalTreeConfig() TreeRenderConfig
- func StandardTreeConfig() TreeRenderConfig
- type TreeSpacingConfig
- type TreeSymbolComponent
- type TreeSymbolConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTreeItemContent ¶
func FormatTreeItemContent( item core.Data[any], index int, depth int, hasChildren, isExpanded bool, renderContext core.RenderContext, isCursor, isTopThreshold, isBottomThreshold bool, formatter TreeItemFormatter, ) string
FormatTreeItemContent provides a default way to format the main content of a tree item. It converts the item's data to a string and appends indicators for states like error, loading, or selection based on the render context.
func TreeEnumerator
deprecated
TreeEnumerator is a legacy enumerator function that creates a tree-style prefix with indentation and expand/collapse symbols.
Deprecated: Use the component-based rendering system with `TreeIndentationComponent` and `TreeSymbolComponent` for more flexibility.
func TreeExpandedEnumerator
deprecated
TreeExpandedEnumerator is a legacy enumerator that uses box-drawing characters to create a connected tree look.
Deprecated: Use the component-based rendering system and set `TreeIndentationConfig.UseConnectors` to true.
func TreeMinimalEnumerator
deprecated
Types ¶
type FlatTreeItem ¶
type FlatTreeItem[T any] struct { ID string Item T Depth int HasChildNodes bool // Renamed to avoid conflict with method Expanded bool ParentID string }
FlatTreeItem represents a tree node within the flattened, linear view used for rendering. It contains the original item data, along with metadata about its position in the tree, such as depth and expansion state.
func (FlatTreeItem[T]) GetDepth ¶
func (f FlatTreeItem[T]) GetDepth() int
GetDepth returns the indentation level of this tree item.
func (FlatTreeItem[T]) HasChildren ¶
func (f FlatTreeItem[T]) HasChildren() bool
HasChildren returns true if this item has child nodes.
func (FlatTreeItem[T]) IsExpanded ¶
func (f FlatTreeItem[T]) IsExpanded() bool
IsExpanded returns true if this item is currently expanded.
type TreeBackgroundComponent ¶
type TreeBackgroundComponent struct {
// contains filtered or unexported fields
}
TreeBackgroundComponent is a special render component that applies a background style as a post-processing step. It can apply the style to the entire line or to a select subset of the other rendered components.
func NewTreeBackgroundComponent ¶
func NewTreeBackgroundComponent(config TreeBackgroundConfig) *TreeBackgroundComponent
NewTreeBackgroundComponent creates a new background component for trees.
func (*TreeBackgroundComponent) GetType ¶
func (c *TreeBackgroundComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeBackgroundComponent) IsEnabled ¶
func (c *TreeBackgroundComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeBackgroundComponent) Render ¶
func (c *TreeBackgroundComponent) Render(ctx TreeComponentContext) string
Render applies the background style according to the configured mode. It does not return its own content but rather modifies the combined output of other components.
func (*TreeBackgroundComponent) SetEnabled ¶
func (c *TreeBackgroundComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeBackgroundConfig ¶
type TreeBackgroundConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// Style is the background style to apply.
Style lipgloss.Style
// ApplyToComponents specifies which other components the background should
// be applied to when using `TreeBackgroundSelectiveComponents` mode.
ApplyToComponents []TreeComponentType
// Mode determines how the background style is applied.
Mode TreeBackgroundMode
}
TreeBackgroundConfig configures the component that applies a background style to the rendered item, acting as a post-processing step.
type TreeBackgroundMode ¶
type TreeBackgroundMode int
TreeBackgroundMode defines how the background style is applied to an item.
const ( // TreeBackgroundEntireLine applies the style to the entire rendered line. TreeBackgroundEntireLine TreeBackgroundMode = iota // TreeBackgroundSelectiveComponents applies the style only to a specified // subset of components. TreeBackgroundSelectiveComponents // TreeBackgroundContentOnly applies the style only to the main content. TreeBackgroundContentOnly // TreeBackgroundIndicatorOnly applies the style only to the cursor indicator. TreeBackgroundIndicatorOnly )
Constants for background styling modes.
type TreeComponentContext ¶
type TreeComponentContext struct {
// Item is the core data for the node being rendered.
Item core.Data[any]
// Index is the absolute linear index of the item in the flattened view.
Index int
// IsCursor is true if this item is currently under the cursor.
IsCursor bool
// IsSelected is true if this item is currently selected.
IsSelected bool
// IsThreshold is true if this item is at a scroll threshold.
IsThreshold bool
// Depth is the level of the node in the tree hierarchy (root is 0).
Depth int
// HasChildren is true if the node has child nodes.
HasChildren bool
// IsExpanded is true if the node is currently expanded to show its children.
IsExpanded bool
// ParentID is the ID of the parent node.
ParentID string
// RenderContext provides global rendering information like theming and
// utility functions.
RenderContext core.RenderContext
// ComponentData is a map containing the rendered output of preceding
// components in the pipeline, allowing subsequent components to make layout
// decisions based on the width of earlier ones (e.g., for text wrapping).
ComponentData map[TreeComponentType]string
// TreeConfig holds the current rendering configuration for the tree.
TreeConfig TreeRenderConfig
}
TreeComponentContext provides all the necessary data for a TreeRenderComponent to render its output. It encapsulates item-specific data, tree structure information, and global rendering settings.
type TreeComponentRenderer ¶
type TreeComponentRenderer struct {
// contains filtered or unexported fields
}
TreeComponentRenderer manages the rendering pipeline for a tree item. It holds all the individual render components and processes them in a defined order to construct the final string for a single tree item.
func NewTreeComponentRenderer ¶
func NewTreeComponentRenderer(config TreeRenderConfig) *TreeComponentRenderer
NewTreeComponentRenderer creates a new renderer with a given configuration, initializing all the necessary components for tree rendering.
func (*TreeComponentRenderer) DisableComponent ¶
func (r *TreeComponentRenderer) DisableComponent(componentType TreeComponentType)
DisableComponent deactivates a specific component.
func (*TreeComponentRenderer) EnableComponent ¶
func (r *TreeComponentRenderer) EnableComponent(componentType TreeComponentType)
EnableComponent activates a specific component in the rendering pipeline.
func (*TreeComponentRenderer) GetComponent ¶
func (r *TreeComponentRenderer) GetComponent(componentType TreeComponentType) TreeRenderComponent
GetComponent retrieves a specific component from the renderer, allowing for direct configuration changes.
func (*TreeComponentRenderer) Render ¶
func (r *TreeComponentRenderer) Render( item core.Data[any], index int, depth int, hasChildren, isExpanded bool, renderContext core.RenderContext, isCursor, isTopThreshold, isBottomThreshold bool, ) string
Render executes the full rendering pipeline for a single tree item. It iterates through the components in the configured order, calls their `Render` methods, and assembles the final string. It handles special cases like the background component, which modifies the output of other components.
func (*TreeComponentRenderer) SetComponentOrder ¶
func (r *TreeComponentRenderer) SetComponentOrder(order []TreeComponentType)
SetComponentOrder defines the sequence in which the components are rendered.
func (*TreeComponentRenderer) UpdateConfig ¶
func (r *TreeComponentRenderer) UpdateConfig(config TreeRenderConfig)
UpdateConfig applies a new configuration to the renderer, recreating all its internal components to reflect the changes.
type TreeComponentType ¶
type TreeComponentType string
TreeComponentType is a string identifier for a specific type of tree rendering component. It is used to define the rendering order and to configure individual components.
const ( // TreeComponentCursor handles the rendering of the cursor indicator. TreeComponentCursor TreeComponentType = "cursor" // TreeComponentPreSpacing adds spacing before the main content. TreeComponentPreSpacing TreeComponentType = "pre_spacing" // TreeComponentIndentation renders the indentation based on the node's depth. TreeComponentIndentation TreeComponentType = "indentation" // TreeComponentTreeSymbol renders the expand/collapse/leaf symbol. TreeComponentTreeSymbol TreeComponentType = "tree_symbol" // TreeComponentEnumerator renders a prefix like a bullet or number. TreeComponentEnumerator TreeComponentType = "enumerator" // TreeComponentContent renders the main item content. TreeComponentContent TreeComponentType = "content" // TreeComponentPostSpacing adds spacing after the main content. TreeComponentPostSpacing TreeComponentType = "post_spacing" // TreeComponentBackground applies background styling as a final step. TreeComponentBackground TreeComponentType = "background" )
Constants defining the available component types for the tree.
type TreeConfig ¶
type TreeConfig struct {
// RenderConfig defines the component-based rendering pipeline for the tree.
RenderConfig TreeRenderConfig
// CascadingSelection, when true, causes selecting a parent node to
// automatically select all of its descendant nodes.
CascadingSelection bool
// AutoExpand, when true, automatically expands a collapsed node when the
// cursor moves to it.
AutoExpand bool
// ShowRoot, when true, applies special styling to root-level nodes.
ShowRoot bool
// ExpandOnSelect, when true, expands or collapses a node when it is selected.
ExpandOnSelect bool
// The fields below are legacy and kept for backward compatibility. The
// component-based rendering system in `TreeRenderConfig` is now the
// preferred way to control appearance.
Enumerator tree.Enumerator
Indenter tree.Indenter
RootStyle lipgloss.Style
ItemStyle lipgloss.Style
EnumeratorStyle lipgloss.Style
CursorIndicator string
CursorSpacing string
NormalSpacing string
ShowCursor bool
EnableCursorStyling bool
CursorBackgroundStyle lipgloss.Style
}
TreeConfig contains configuration options specific to the TreeList component, primarily related to rendering and interaction with the tree structure.
func DefaultTreeConfig ¶
func DefaultTreeConfig() TreeConfig
DefaultTreeConfig returns a set of sensible default configurations for a TreeList.
type TreeContentComponent ¶
type TreeContentComponent struct {
// contains filtered or unexported fields
}
TreeContentComponent is the render component responsible for displaying the main content of the tree item. It uses a provided formatter or a default formatting logic and can handle text wrapping.
func NewTreeContentComponent ¶
func NewTreeContentComponent(config TreeContentConfig) *TreeContentComponent
NewTreeContentComponent creates a new content component for trees.
func (*TreeContentComponent) GetType ¶
func (c *TreeContentComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeContentComponent) IsEnabled ¶
func (c *TreeContentComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeContentComponent) Render ¶
func (c *TreeContentComponent) Render(ctx TreeComponentContext) string
Render generates the item's main content string. If text wrapping is enabled, it will wrap the text and indent subsequent lines to align with the start of the content.
func (*TreeContentComponent) SetEnabled ¶
func (c *TreeContentComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeContentConfig ¶
type TreeContentConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// Formatter is the function that generates the content string from the item data.
Formatter TreeItemFormatter
// Style is the lipgloss style applied to the content.
Style lipgloss.Style
// WrapText enables or disables text wrapping for the content.
WrapText bool
// MaxWidth is the width at which text wrapping will occur.
MaxWidth int
}
TreeContentConfig configures the component that renders the main content of the tree item.
type TreeCursorComponent ¶
type TreeCursorComponent struct {
// contains filtered or unexported fields
}
TreeCursorComponent is a render component responsible for displaying the cursor indicator for a tree item. It shows a specific string when the item is under the cursor and a different string otherwise to ensure alignment.
func NewTreeCursorComponent ¶
func NewTreeCursorComponent(config TreeCursorConfig) *TreeCursorComponent
NewTreeCursorComponent creates a new cursor component with the given configuration.
func (*TreeCursorComponent) GetType ¶
func (c *TreeCursorComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeCursorComponent) IsEnabled ¶
func (c *TreeCursorComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeCursorComponent) Render ¶
func (c *TreeCursorComponent) Render(ctx TreeComponentContext) string
Render returns the cursor indicator string based on the context.
func (*TreeCursorComponent) SetEnabled ¶
func (c *TreeCursorComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeCursorConfig ¶
type TreeCursorConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// CursorIndicator is the string shown when the item is under the cursor.
CursorIndicator string
// NormalSpacing is the string used for alignment when the item is not under
// the cursor.
NormalSpacing string
// Style is the lipgloss style applied to the component's output.
Style lipgloss.Style
// ShowOnlyAtRoot, if true, restricts the cursor indicator to only be shown
// for root-level nodes.
ShowOnlyAtRoot bool
}
TreeCursorConfig configures the appearance and behavior of the cursor component.
type TreeData ¶
TreeData represents a single node in a hierarchical dataset. It contains the item's data, its unique ID, and a slice of its children, forming the fundamental structure for the tree.
type TreeDataSource ¶
type TreeDataSource[T any] interface { // GetRootNodes returns the top-level nodes of the tree. GetRootNodes() []TreeData[T] // GetItemByID retrieves a specific tree node by its unique ID. GetItemByID(id string) (TreeData[T], bool) // SetSelected sends a command to update the selection state of a node by its ID. SetSelected(id string, selected bool) tea.Cmd // SetSelectedByID is an alias for SetSelected. SetSelectedByID(id string, selected bool) tea.Cmd // SelectAll sends a command to select all nodes. SelectAll() tea.Cmd // ClearSelection sends a command to clear all selections. ClearSelection() tea.Cmd // SelectRange sends a command to select a range of nodes between two IDs. SelectRange(startID, endID string) tea.Cmd }
TreeDataSource defines the contract for providing hierarchical data to the TreeList component. Implementations are responsible for fetching the tree structure and handling operations like selection.
type TreeEnumeratorAlignment ¶
type TreeEnumeratorAlignment int
TreeEnumeratorAlignment defines the horizontal alignment for the enumerator.
const ( TreeAlignmentNone TreeEnumeratorAlignment = iota TreeAlignmentLeft TreeAlignmentRight )
Constants for enumerator alignment.
type TreeEnumeratorComponent ¶
type TreeEnumeratorComponent struct {
// contains filtered or unexported fields
}
TreeEnumeratorComponent is a render component that displays an enumerator, such as a bullet point or number, next to the tree item. The appearance is determined by a provided `TreeEnumeratorFunc`.
func NewTreeEnumeratorComponent ¶
func NewTreeEnumeratorComponent(config TreeEnumeratorConfig) *TreeEnumeratorComponent
NewTreeEnumeratorComponent creates a new enumerator component for trees.
func (*TreeEnumeratorComponent) GetType ¶
func (c *TreeEnumeratorComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeEnumeratorComponent) IsEnabled ¶
func (c *TreeEnumeratorComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeEnumeratorComponent) Render ¶
func (c *TreeEnumeratorComponent) Render(ctx TreeComponentContext) string
Render generates the enumerator string using the configured function and applies any specified alignment.
func (*TreeEnumeratorComponent) SetEnabled ¶
func (c *TreeEnumeratorComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeEnumeratorConfig ¶
type TreeEnumeratorConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// Enumerator is the function that generates the enumerator string.
Enumerator TreeEnumeratorFunc
// Style is the lipgloss style applied to the enumerator.
Style lipgloss.Style
// Alignment controls the horizontal alignment of the enumerator string.
Alignment TreeEnumeratorAlignment
// MaxWidth is the maximum width for the enumerator, used for alignment.
MaxWidth int
}
TreeEnumeratorConfig configures the component that renders an enumerator (e.g., bullet, number) for each tree item.
type TreeEnumeratorFunc ¶
type TreeEnumeratorFunc func(item core.Data[any], index int, depth int, hasChildren, isExpanded bool, ctx core.RenderContext) string
TreeEnumeratorFunc is a function type for generating an enumerator string, receiving tree-specific context like depth and expansion state.
type TreeIndentationComponent ¶
type TreeIndentationComponent struct {
// contains filtered or unexported fields
}
TreeIndentationComponent is a render component that generates the indentation string for a tree node, visually representing its depth in the hierarchy. It can use either simple spacing or box-drawing characters for a connected look.
func NewTreeIndentationComponent ¶
func NewTreeIndentationComponent(config TreeIndentationConfig) *TreeIndentationComponent
NewTreeIndentationComponent creates a new indentation component.
func (*TreeIndentationComponent) GetType ¶
func (c *TreeIndentationComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeIndentationComponent) IsEnabled ¶
func (c *TreeIndentationComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeIndentationComponent) Render ¶
func (c *TreeIndentationComponent) Render(ctx TreeComponentContext) string
Render generates the indentation string based on the node's depth and the component's configuration.
func (*TreeIndentationComponent) SetEnabled ¶
func (c *TreeIndentationComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeIndentationConfig ¶
type TreeIndentationConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// IndentString is the string repeated for each level of indentation when
// UseConnectors is false.
IndentString string
// IndentSize is the number of spaces used for each indentation level if
// IndentString is empty.
IndentSize int
// Style is the lipgloss style for the indentation.
Style lipgloss.Style
// ConnectorStyle is the style applied to box-drawing characters if
// UseConnectors is true.
ConnectorStyle lipgloss.Style
// UseConnectors, if true, renders indentation using box-drawing characters
// to create a classic tree look.
UseConnectors bool
}
TreeIndentationConfig configures the component responsible for rendering the indentation that visually represents the tree's hierarchy.
type TreeItemFormatter ¶
type TreeItemFormatter func(item core.Data[any], index int, depth int, hasChildren, isExpanded bool, ctx core.RenderContext, isCursor, isTopThreshold, isBottomThreshold bool) string
TreeItemFormatter is a function type for rendering the main content of a tree item, receiving full tree-specific context.
func ComponentBasedTreeFormatter ¶
func ComponentBasedTreeFormatter(config TreeRenderConfig) TreeItemFormatter
ComponentBasedTreeFormatter creates a `TreeItemFormatter` function from a `TreeRenderConfig`. This allows the component-based rendering pipeline to be used as a standard formatter, providing an integration point with systems that expect a single formatting function.
func EnhancedTreeFormatter ¶
func EnhancedTreeFormatter(config TreeRenderConfig) TreeItemFormatter
EnhancedTreeFormatter is an alias for `ComponentBasedTreeFormatter`. It serves as the primary entry point for using the component-based rendering system.
type TreeList ¶
type TreeList[T any] struct { // contains filtered or unexported fields }
TreeList is a stateful Bubble Tea component that displays a scrollable, hierarchical list. It manages tree-specific state like node expansion and selection, flattens the tree structure for efficient rendering, and reuses core list functionalities for viewport management, data virtualization, and user interactions.
func NewTreeList ¶
func NewTreeList[T any](listConfig core.ListConfig, treeConfig TreeConfig, dataSource TreeDataSource[T]) *TreeList[T]
NewTreeList creates a new TreeList component with the given configurations and data source. It initializes the tree's state, flattens the initial view, and sets up the rendering context.
func (*TreeList[T]) Blur ¶
func (tl *TreeList[T]) Blur()
Blur removes focus from the tree, preventing it from handling keyboard inputs.
func (*TreeList[T]) CollapseAll ¶
CollapseAll collapses all nodes in the entire tree.
func (*TreeList[T]) CollapseCurrentSubtree ¶
CollapseCurrentSubtree collapses the current node and all its descendants.
func (*TreeList[T]) CollapseNode ¶
CollapseNode collapses a tree node specified by its ID, hiding its children. It then updates the flattened view and refreshes the data.
func (*TreeList[T]) CollapseSubtree ¶
CollapseSubtree collapses a node and all of its descendants recursively.
func (*TreeList[T]) ExpandCurrentSubtree ¶
ExpandCurrentSubtree expands the current node and all its descendants.
func (*TreeList[T]) ExpandNode ¶
ExpandNode expands a tree node specified by its ID, revealing its children. It then updates the flattened view and refreshes the data.
func (*TreeList[T]) ExpandSubtree ¶
ExpandSubtree expands a node and all of its descendants recursively.
func (*TreeList[T]) Focus ¶
Focus sets the tree to a focused state, allowing it to receive and handle keyboard inputs.
func (*TreeList[T]) GetAutoExpand ¶
GetAutoExpand returns whether auto-expansion is currently enabled.
func (*TreeList[T]) GetCascadingSelection ¶
GetCascadingSelection returns whether cascading selection is currently enabled.
func (*TreeList[T]) GetCurrentNodeID ¶
GetCurrentNodeID returns the ID of the node currently under the cursor. Returns empty string if no valid cursor position.
func (*TreeList[T]) GetExpandOnSelect ¶
GetExpandOnSelect returns whether expand-on-select is currently enabled.
func (*TreeList[T]) GetFullyExpandedItemCount ¶
GetFullyExpandedItemCount returns the total number of items the tree would have if all nodes were expanded.
func (*TreeList[T]) GetRenderConfig ¶
func (tl *TreeList[T]) GetRenderConfig() TreeRenderConfig
GetRenderConfig returns the current tree rendering configuration.
func (*TreeList[T]) GetSelectionCount ¶
GetSelectionCount returns the number of currently selected nodes.
func (*TreeList[T]) GetState ¶
func (tl *TreeList[T]) GetState() core.ViewportState
GetState returns the current state of the viewport, including cursor position and scroll offset.
func (*TreeList[T]) Init ¶
Init initializes the TreeList component, loading the initial data. It is part of the bubbletea.Model interface.
func (*TreeList[T]) JumpToIndexExpandingParents ¶
JumpToIndexExpandingParents creates a command to jump to a specific index in the conceptual "fully expanded" tree. It automatically expands all parent nodes necessary to make the target item visible.
func (*TreeList[T]) SetAutoExpand ¶
SetAutoExpand enables or disables the automatic expansion of nodes when the cursor moves to them.
func (*TreeList[T]) SetCascadingSelection ¶
SetCascadingSelection enables or disables the automatic selection of child nodes when a parent is selected.
func (*TreeList[T]) SetExpandOnSelect ¶
SetExpandOnSelect enables or disables expanding/collapsing a node when it is selected.
func (*TreeList[T]) SetRenderConfig ¶
func (tl *TreeList[T]) SetRenderConfig(config TreeRenderConfig)
SetRenderConfig applies a completely new rendering configuration for the tree.
func (*TreeList[T]) SetTreeEnumerator ¶
func (tl *TreeList[T]) SetTreeEnumerator()
SetTreeEnumerator configures the tree to use a basic tree-style enumerator.
func (*TreeList[T]) SetTreeExpandedEnumerator ¶
func (tl *TreeList[T]) SetTreeExpandedEnumerator()
SetTreeExpandedEnumerator configures the tree to use an enumerator with box-drawing characters for a connected look.
func (*TreeList[T]) SetTreeMinimalEnumerator ¶
func (tl *TreeList[T]) SetTreeMinimalEnumerator()
SetTreeMinimalEnumerator configures the tree to use a minimal enumerator style.
func (*TreeList[T]) ToggleCurrentNode ¶
ToggleCurrentNode toggles the expansion state of the node currently under the cursor.
func (*TreeList[T]) ToggleNode ¶
ToggleNode toggles the expansion state of a tree node specified by its ID.
type TreePostSpacingComponent ¶
type TreePostSpacingComponent struct {
// contains filtered or unexported fields
}
TreePostSpacingComponent is a render component that adds a fixed-width space after the main content.
func NewTreePostSpacingComponent ¶
func NewTreePostSpacingComponent(config TreeSpacingConfig) *TreePostSpacingComponent
NewTreePostSpacingComponent creates a new post-spacing component.
func (*TreePostSpacingComponent) GetType ¶
func (c *TreePostSpacingComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreePostSpacingComponent) IsEnabled ¶
func (c *TreePostSpacingComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreePostSpacingComponent) Render ¶
func (c *TreePostSpacingComponent) Render(ctx TreeComponentContext) string
Render returns the configured spacing string.
func (*TreePostSpacingComponent) SetEnabled ¶
func (c *TreePostSpacingComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreePreSpacingComponent ¶
type TreePreSpacingComponent struct {
// contains filtered or unexported fields
}
TreePreSpacingComponent is a render component that adds a fixed-width space before the main content, useful for creating indentation or alignment.
func NewTreePreSpacingComponent ¶
func NewTreePreSpacingComponent(config TreeSpacingConfig) *TreePreSpacingComponent
NewTreePreSpacingComponent creates a new pre-spacing component.
func (*TreePreSpacingComponent) GetType ¶
func (c *TreePreSpacingComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreePreSpacingComponent) IsEnabled ¶
func (c *TreePreSpacingComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreePreSpacingComponent) Render ¶
func (c *TreePreSpacingComponent) Render(ctx TreeComponentContext) string
Render returns the configured spacing string.
func (*TreePreSpacingComponent) SetEnabled ¶
func (c *TreePreSpacingComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeRenderComponent ¶
type TreeRenderComponent interface {
// Render generates the string content for this component based on the
// provided context.
Render(ctx TreeComponentContext) string
// GetType returns the component's unique type identifier, used for ordering
// and configuration.
GetType() TreeComponentType
// IsEnabled returns whether this component should be rendered.
IsEnabled() bool
// SetEnabled allows enabling or disabling this component at runtime.
SetEnabled(enabled bool)
}
TreeRenderComponent defines the contract for a single, modular part of a rendered tree item. Implementations of this interface are responsible for generating a specific piece of the final string output, such as the cursor indicator or the indentation.
type TreeRenderConfig ¶
type TreeRenderConfig struct {
// ComponentOrder defines the sequence in which the components are rendered.
ComponentOrder []TreeComponentType
// Component configurations for each part of the tree item.
CursorConfig TreeCursorConfig
PreSpacingConfig TreeSpacingConfig
IndentationConfig TreeIndentationConfig
TreeSymbolConfig TreeSymbolConfig
EnumeratorConfig TreeEnumeratorConfig
ContentConfig TreeContentConfig
PostSpacingConfig TreeSpacingConfig
BackgroundConfig TreeBackgroundConfig
}
TreeRenderConfig holds the complete configuration for the component-based rendering pipeline of the tree. It defines which components are active, their order, and their individual settings.
func BackgroundStyledTreeConfig ¶
func BackgroundStyledTreeConfig(style lipgloss.Style, mode TreeBackgroundMode) TreeRenderConfig
BackgroundStyledTreeConfig creates a `TreeRenderConfig` that applies a background style to tree items. The mode determines whether the style applies to the entire line or just specific components.
func DefaultTreeRenderConfig ¶
func DefaultTreeRenderConfig() TreeRenderConfig
DefaultTreeRenderConfig returns a sensible default configuration for a component-based tree, featuring a cursor, indentation, tree symbols, and content.
func EnumeratedTreeConfig ¶
func EnumeratedTreeConfig(enumerator TreeEnumeratorFunc) TreeRenderConfig
EnumeratedTreeConfig creates a `TreeRenderConfig` that includes an enumerator component, allowing for numbered or bulleted tree items.
func MinimalTreeConfig ¶
func MinimalTreeConfig() TreeRenderConfig
MinimalTreeConfig provides a pre-configured `TreeRenderConfig` with only indentation and content enabled, for a clean, simple look.
func StandardTreeConfig ¶
func StandardTreeConfig() TreeRenderConfig
StandardTreeConfig provides a pre-configured `TreeRenderConfig` that uses box-drawing characters for a classic, connected tree appearance.
type TreeSpacingConfig ¶
type TreeSpacingConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// Spacing is the string to be rendered, typically composed of spaces.
Spacing string
// Style is the lipgloss style applied to the spacing.
Style lipgloss.Style
}
TreeSpacingConfig configures a spacing component, used for adding horizontal space (padding) within the rendered item line.
type TreeSymbolComponent ¶
type TreeSymbolComponent struct {
// contains filtered or unexported fields
}
TreeSymbolComponent is a render component that displays a symbol indicating the state of a tree node (e.g., expanded, collapsed, or a leaf).
func NewTreeSymbolComponent ¶
func NewTreeSymbolComponent(config TreeSymbolConfig) *TreeSymbolComponent
NewTreeSymbolComponent creates a new tree symbol component.
func (*TreeSymbolComponent) GetType ¶
func (c *TreeSymbolComponent) GetType() TreeComponentType
GetType returns the unique type identifier for this component.
func (*TreeSymbolComponent) IsEnabled ¶
func (c *TreeSymbolComponent) IsEnabled() bool
IsEnabled checks if the component is configured to be rendered.
func (*TreeSymbolComponent) Render ¶
func (c *TreeSymbolComponent) Render(ctx TreeComponentContext) string
Render generates the symbol string based on the node's state (e.g., has children, is expanded).
func (*TreeSymbolComponent) SetEnabled ¶
func (c *TreeSymbolComponent) SetEnabled(enabled bool)
SetEnabled allows enabling or disabling this component at runtime.
type TreeSymbolConfig ¶
type TreeSymbolConfig struct {
// Enabled toggles the rendering of this component.
Enabled bool
// ExpandedSymbol is the string shown for an expanded node (e.g., "▼").
ExpandedSymbol string
// CollapsedSymbol is the string shown for a collapsed node (e.g., "▶").
CollapsedSymbol string
// LeafSymbol is the string shown for a node with no children.
LeafSymbol string
// Style is the lipgloss style applied to the symbol.
Style lipgloss.Style
// ShowForLeaves, if true, renders the LeafSymbol for nodes without children.
ShowForLeaves bool
// SymbolSpacing is a string (usually a space) added after the symbol for
// padding.
SymbolSpacing string
}
TreeSymbolConfig configures the component that displays symbols indicating a node's state (expanded, collapsed, or leaf).