package tree
import (
)
type StyleFunc func(children Children, i int) lipgloss.Style
type Style struct {
enumeratorFunc StyleFunc
indenterFunc StyleFunc
itemFunc StyleFunc
root lipgloss.Style
}
func () *renderer {
return &renderer{
style: Style{
enumeratorFunc: func(Children, int) lipgloss.Style {
return lipgloss.NewStyle().PaddingRight(1)
},
indenterFunc: func(Children, int) lipgloss.Style {
return lipgloss.NewStyle().PaddingRight(1)
},
itemFunc: func(Children, int) lipgloss.Style {
return lipgloss.NewStyle()
},
},
enumerator: DefaultEnumerator,
indenter: DefaultIndenter,
}
}
type renderer struct {
style Style
enumerator Enumerator
indenter Indenter
width int
}
func ( *renderer) ( Node, bool, string) string {
if .Hidden() {
return ""
}
var int
:= .Children()
:= .enumerator
:= .indenter
:= make([]string, 0, .Length())
if := .Value(); != "" && {
:= .style.root.Render()
if := .width - lipgloss.Width(); > 0 {
= + .style.root.Render(strings.Repeat(" ", ))
}
= append(, .style.root.Render())
}
for := range .Length() {
if < .Length()-1 {
if := .At( + 1); .Hidden() {
= .(NodeChildren).Remove( + 1)
}
}
:= (, )
= .style.enumeratorFunc(, ).Render()
= max(lipgloss.Width(), )
}
for := range .Length() {
:= .At()
if .Hidden() {
continue
}
:= .style.indenterFunc(, )
:= .style.enumeratorFunc(, )
:= .style.itemFunc(, )
:= .Render((, ))
:= .Render((, ))
:= lipgloss.NewStyle().Background(.GetBackground())
if := - lipgloss.Width(); > 0 {
= .Render(strings.Repeat(" ", )) +
}
:= .Render(.Value())
:= .Render()
for lipgloss.Height() > lipgloss.Height() {
= lipgloss.JoinVertical(
lipgloss.Left,
,
,
)
}
for lipgloss.Height() > lipgloss.Height() {
= lipgloss.JoinVertical(
lipgloss.Left,
,
,
)
}
:= lipgloss.JoinHorizontal(
lipgloss.Top,
,
,
,
)
if := .width - lipgloss.Width(); > 0 {
= + .Render(strings.Repeat(" ", ))
}
= append(
,
,
)
if .Length() > 0 {
:=
switch child := .(type) {
case *Tree:
if .r != nil {
= .r
}
}
if := .(
,
false,
+,
); != "" {
= append(, )
}
}
}
return strings.Join(, "\n")
}