Add basic navigation to sidebar

This commit is contained in:
vaibhav
2026-01-16 04:16:37 +05:30
parent b92b173815
commit 1f413157ef

View File

@@ -6,24 +6,48 @@ import (
)
type Sidebar struct {
data string
data []string
sindex int
}
func (s Sidebar) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
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 {
sidebar := lipgloss.
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(s.data)
return sidebar
Render(lipgloss.JoinVertical(lipgloss.Left, items...))
}