Skip to content

Tree

Collapsible tree view for hierarchical data with cursor navigation, expand/collapse, and optional icons. Implements Component and Themed.

Construction

tree := blit.NewTree([]*blit.Node{
    {
        Title: "src",
        Expanded: true,
        Children: []*blit.Node{
            {Title: "main.go", Glyph: "📄"},
            {Title: "app.go", Glyph: "📄"},
            {
                Title: "internal",
                Children: []*blit.Node{
                    {Title: "fuzzy.go"},
                },
            },
        },
    },
}, blit.TreeOpts{
    OnSelect: func(node *blit.Node) {
        fmt.Println("Selected:", node.Title)
    },
})

Node

type Node struct {
    Title    string  // Display label
    Glyph    string  // Optional icon prefix
    Children []*Node // Child nodes (non-nil = expandable)
    Data     any     // Arbitrary payload
    Expanded bool    // Whether children are visible
}

TreeOpts

type TreeOpts struct {
    OnSelect func(node *Node) // Called on Enter
    OnToggle func(node *Node) // Called on expand/collapse
}

Keyboard

Key Action
j / k Move cursor down / up
Enter / l Expand node or trigger OnSelect on leaf
h Collapse node
space Toggle expand/collapse

Example

go run ./examples/filetree/