Skip to content

Commit

Permalink
refactor: higher level enumerator
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed May 15, 2024
1 parent 74a5b96 commit a9f7bc2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions examples/list/duckduckgoose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import (
"github.com/charmbracelet/lipgloss/list"
)

func main() {
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")

var DuckDuckGooseEnumerator = func(i int) string {
func DuckDuckGooseEnumerator(l list.List) list.Enumerator {
return func(i int) string {
if l.At(i) == "Goose" {
return "Honk →"
}
return ""
}
}

func main() {
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")

l = l.Enumerator(DuckDuckGooseEnumerator).EnumeratorStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("48")).MarginRight(1))
l = l.Enumerator(DuckDuckGooseEnumerator(l)).EnumeratorStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("48")).MarginRight(1))

fmt.Println(l)
}

0 comments on commit a9f7bc2

Please sign in to comment.