Add basic navigation to sidebar
This commit is contained in:
@@ -6,24 +6,48 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Sidebar struct {
|
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) {
|
switch m := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch m.String() {
|
switch m.String() {
|
||||||
case "up":
|
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 {
|
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().
|
NewStyle().
|
||||||
BorderStyle(lipgloss.NormalBorder()).
|
BorderStyle(lipgloss.NormalBorder()).
|
||||||
Padding(1, 2).
|
Padding(1, 2).
|
||||||
Render(s.data)
|
Render(lipgloss.JoinVertical(lipgloss.Left, items...))
|
||||||
return sidebar
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user