Files
music_player/components/sidebar.go
2026-01-16 04:16:37 +05:30

54 lines
921 B
Go

package components
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type Sidebar struct {
data []string
sindex int
}
func (s Sidebar) Init() tea.Cmd {
return nil
}
func (s *Sidebar) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m := msg.(type) {
case tea.KeyMsg:
switch m.String() {
case "up":
if s.sindex > 0 {
s.sindex--
}
case "down":
if s.sindex < len(s.data)-1 {
s.sindex++
}
}
}
return s, nil
}
func (s Sidebar) View() string {
var items []string
for i, item := range s.data {
if i == s.sindex {
items = append(items, lipgloss.
NewStyle().
Background(lipgloss.Color("93BD57")).
Padding(1, 2).
Render(item))
} else {
items = append(items, item)
}
}
return lipgloss.
NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Padding(1, 2).
Render(lipgloss.JoinVertical(lipgloss.Left, items...))
}