delegate.go (870B)
1 package main 2 3 import ( 4 "fmt" 5 "io" 6 7 "github.com/charmbracelet/bubbles/list" 8 "github.com/charmbracelet/bubbletea" 9 gloss "github.com/charmbracelet/lipgloss" 10 ) 11 12 type itemDelegate struct{} 13 14 func (d itemDelegate) Height() int { return 2 } 15 func (d itemDelegate) Spacing() int { return 1 } 16 func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil } 17 func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { 18 i, ok := listItem.(item) 19 if !ok { 20 return 21 } 22 23 highlight := gloss.NewStyle().Background(gloss.Color("7")).Foreground(gloss.Color("0")) 24 title := fmt.Sprintf("%d. %s", index+1, i.Title()) 25 if index == m.Index() { 26 title = highlight.Render(title) 27 } 28 title = " " + title 29 30 fmt.Fprint(w, title) 31 fmt.Fprint(w, fmt.Sprintf("\n %s", i.Description())) 32 }