treeview

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScrollStep = 5
)

Number of nodes to scroll per mouse wheel event.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a TreeView.

func CollapsedIcon

func CollapsedIcon(icon string) Option

CollapsedIcon sets the icon for collapsed nodes.

func EnableLogging deprecated

func EnableLogging(_ bool) Option

EnableLogging is a no-op kept for backward compatibility. Use LogWriter(w) to capture debug output instead.

Deprecated: use LogWriter.

func ExpandedIcon

func ExpandedIcon(icon string) Option

ExpandedIcon sets the icon for expanded nodes.

func Icons

func Icons(expanded, collapsed, leaf string) Option

Icons sets custom icons for expanded, collapsed, and leaf nodes.

func Indentation

func Indentation(spaces int) Option

Indentation sets the number of spaces for each indentation level.

func IndentationPerLevel

func IndentationPerLevel(spaces int) Option

IndentationPerLevel sets the indentation per level. Alias to Indentation for compatibility with demo code.

func Label

func Label(_ string) Option

Label sets the widget's label. Note: If the widget's label is managed by the container, this can be a no-op.

func LabelColor

func LabelColor(color cell.Color) Option

LabelColor sets the color of the node labels.

func LeafIcon

func LeafIcon(icon string) Option

LeafIcon sets the icon for leaf nodes.

func LogWriter

func LogWriter(w io.Writer) Option

LogWriter directs debug log output to w. Pass io.Discard (or omit the option) to silence all output. New() never opens files on your behalf.

func Nodes

func Nodes(nodes ...*TreeNode) Option

Nodes sets the root nodes of the TreeView.

func Truncate

func Truncate(truncate bool) Option

Truncate enables or disables label truncation.

func WaitingIcons

func WaitingIcons(icons []string) Option

WaitingIcons sets the icons for the spinner.

type TreeNode

type TreeNode struct {
	// ID is the unique identifier for the node.
	ID string
	// Label is the display text of the node.
	Label string
	// Level is the depth level of the node in the tree.
	Level int
	// Parent is the parent node of this node.
	Parent *TreeNode
	// Children are the child nodes of this node.
	Children []*TreeNode
	// Value holds any data associated with the node.
	Value interface{}
	// ShowSpinner indicates whether to display a spinner for this node.
	ShowSpinner bool
	// OnClick is the function to execute when the node is clicked.
	OnClick func() error
	// ExpandedState indicates whether the node is expanded to show its children.
	ExpandedState bool
	// SpinnerIndex is the current index for the spinner icons.
	SpinnerIndex int
	// contains filtered or unexported fields
}

TreeNode represents a node in the treeview.

func (*TreeNode) GetExpandedState

func (tn *TreeNode) GetExpandedState() bool

GetExpandedState safely retrieves the ExpandedState flag.

func (*TreeNode) GetShowSpinner

func (tn *TreeNode) GetShowSpinner() bool

GetShowSpinner safely retrieves the ShowSpinner flag.

func (*TreeNode) GetSpinnerIndex

func (tn *TreeNode) GetSpinnerIndex() int

GetSpinnerIndex safely retrieves the current SpinnerIndex.

func (*TreeNode) IncrementSpinner

func (tn *TreeNode) IncrementSpinner(totalIcons int)

IncrementSpinner safely increments the SpinnerIndex.

func (*TreeNode) IsRoot

func (tn *TreeNode) IsRoot() bool

IsRoot checks if the node is a root node.

func (*TreeNode) SetExpandedState

func (tn *TreeNode) SetExpandedState(value bool)

SetExpandedState safely sets the ExpandedState flag.

func (*TreeNode) SetShowSpinner

func (tn *TreeNode) SetShowSpinner(value bool)

SetShowSpinner safely sets the ShowSpinner flag.

type TreeView

type TreeView struct {
	// contains filtered or unexported fields
}

TreeView represents the treeview widget.

func New

func New(opts ...Option) (*TreeView, error)

New creates a new TreeView instance.

func (*TreeView) Draw

func (tv *TreeView) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw renders the treeview widget.

func (*TreeView) Keyboard

func (tv *TreeView) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard handles keyboard events.

func (*TreeView) Mouse

func (tv *TreeView) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse handles mouse events with debouncing for ButtonLeft clicks. It processes mouse press events and mouse wheel events.

func (*TreeView) Next

func (tv *TreeView) Next()

Next moves the selection down.

func (*TreeView) Options

func (tv *TreeView) Options() widgetapi.Options

Options returns the widget options to satisfy the widgetapi.Widget interface.

func (*TreeView) Previous

func (tv *TreeView) Previous()

Previous moves the selection up.

func (*TreeView) Select

func (tv *TreeView) Select() (string, error)

Select returns the label of the selected node.

func (*TreeView) StopSpinnerTicker

func (tv *TreeView) StopSpinnerTicker()

StopSpinnerTicker is a no-op kept for backward compatibility. The spinner is now driven by Draw() rather than a background goroutine.

Directories

Path Synopsis
treeviewdemo.go
treeviewdemo.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL