Skip to content

Commit

Permalink
feat(tree): example showing items in open and closed states (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Apr 18, 2024
1 parent 04ada29 commit b243fb1
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/tree/states/main.go
@@ -0,0 +1,62 @@
package main

import (
"fmt"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/tree"
)

func openEnumerator(data tree.Data, i int) (indent, prefix string) {
if data.Length()-1 == i {
return " ", "▼ "
}
return " ", "▼ "
}

func closedEnumerator(data tree.Data, i int) (indent, prefix string) {
if data.Length()-1 == i {
return " ", "▶ "
}
return " ", "▶ "
}

func normalEnumerator(data tree.Data, _ int) (indent, prefix string) {
return " ", "• "
}

func main() {
pink := lipgloss.NewStyle().MarginRight(1)
gray := lipgloss.NewStyle().Foreground(lipgloss.Color("8")).MarginRight(1)

t := tree.New().
Root("Groceries").
Items(
tree.New().
Root("Fruits").
Items(
"Blood Orange",
"Papaya",
"Dragonfruit",
"Yuzu",
).EnumeratorStyle(gray).Enumerator(normalEnumerator),
tree.New().
Root("Items").
Items(
"Cat Food",
"Nutella",
"Powdered Sugar",
).EnumeratorStyle(gray).Enumerator(closedEnumerator).Hide(true),
tree.New().
Root("Veggies").
Items(
"Leek",
"Artichoke",
).EnumeratorStyle(gray).Enumerator(normalEnumerator),
).
ItemStyle(pink).
EnumeratorStyle(gray).
Enumerator(openEnumerator)

fmt.Println(t)
}

0 comments on commit b243fb1

Please sign in to comment.