mirror of
https://github.com/taigrr/gico.git
synced 2026-04-01 18:58:59 -07:00
make highlight color of active list responsive
This commit is contained in:
@@ -8,7 +8,13 @@ import (
|
|||||||
tea "github.com/charmbracelet/bubbletea"
|
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 }
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +42,7 @@ func (s selectableDelegate) Render(w io.Writer, m list.Model, index int, item li
|
|||||||
str += " [ ] "
|
str += " [ ] "
|
||||||
}
|
}
|
||||||
str += x.text
|
str += x.text
|
||||||
if m.Index() == index {
|
if s.IsActiveList && m.Index() == index {
|
||||||
sty := list.NewDefaultItemStyles()
|
sty := list.NewDefaultItemStyles()
|
||||||
str = sty.SelectedTitle.Render(str)
|
str = sty.SelectedTitle.Render(str)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,12 @@ func (m Settings) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
if msg.String() == "tab" {
|
if msg.String() == "tab" {
|
||||||
if m.cursor == authors {
|
if m.cursor == authors {
|
||||||
m.cursor = repos
|
m.cursor = repos
|
||||||
|
m.AuthorList.SetDelegate(selectableDelegate{IsActiveList: false})
|
||||||
|
m.RepoList.SetDelegate(selectableDelegate{IsActiveList: true})
|
||||||
} else {
|
} else {
|
||||||
m.cursor = authors
|
m.cursor = authors
|
||||||
|
m.AuthorList.SetDelegate(selectableDelegate{IsActiveList: true})
|
||||||
|
m.RepoList.SetDelegate(selectableDelegate{IsActiveList: false})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,12 +197,12 @@ func NewSettings() (Settings, error) {
|
|||||||
for _, v := range m.AllRepos {
|
for _, v := range m.AllRepos {
|
||||||
repoItems = append(repoItems, v)
|
repoItems = append(repoItems, v)
|
||||||
}
|
}
|
||||||
m.RepoList = list.New(repoItems, selectableDelegate{}, 0, 4)
|
m.RepoList = list.New(repoItems, selectableDelegate{IsActiveList: false}, 0, 4)
|
||||||
|
|
||||||
authItems := []list.Item{}
|
authItems := []list.Item{}
|
||||||
for _, v := range m.AllAuthors {
|
for _, v := range m.AllAuthors {
|
||||||
authItems = append(authItems, v)
|
authItems = append(authItems, v)
|
||||||
}
|
}
|
||||||
m.AuthorList = list.New(authItems, selectableDelegate{}, 0, 4)
|
m.AuthorList = list.New(authItems, selectableDelegate{IsActiveList: true}, 0, 4)
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user