make highlight color of active list responsive

This commit is contained in:
2023-03-04 12:05:29 -08:00
parent 5ce5ff29ea
commit b83c52ab50
2 changed files with 18 additions and 4 deletions

View File

@@ -8,7 +8,13 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
type selectableDelegate struct{}
type SelectionMsg struct {
IsSelected bool
}
type selectableDelegate struct {
IsActiveList bool
}
func (s selectableDelegate) Height() int { return 1 }
@@ -17,6 +23,10 @@ func (s selectableDelegate) Spacing() int {
}
func (s selectableDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
if msg, ok := msg.(SelectionMsg); ok {
s.IsActiveList = msg.IsSelected
m.SetDelegate(s)
}
return nil
}
@@ -32,7 +42,7 @@ func (s selectableDelegate) Render(w io.Writer, m list.Model, index int, item li
str += " [ ] "
}
str += x.text
if m.Index() == index {
if s.IsActiveList && m.Index() == index {
sty := list.NewDefaultItemStyles()
str = sty.SelectedTitle.Render(str)
}