ficsit-cli-flake/tea/utils/lists.go

56 lines
1.3 KiB
Go
Raw Normal View History

2021-12-02 04:00:33 +00:00
package utils
import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
2022-04-14 01:27:39 +00:00
var _ list.DefaultItem = (*SimpleItem[tea.Model])(nil)
2021-12-02 04:00:33 +00:00
2022-04-14 01:27:39 +00:00
type SimpleItem[T tea.Model] struct {
Activate func(msg tea.Msg, currentModel T) (tea.Model, tea.Cmd)
2022-10-14 16:11:16 +00:00
ItemTitle string
2022-04-14 01:27:39 +00:00
}
2021-12-04 03:42:31 +00:00
2022-04-14 01:27:39 +00:00
type SimpleItemExtra[T tea.Model, E any] struct {
Extra E
2022-10-14 16:11:16 +00:00
SimpleItem[T]
2021-12-04 03:42:31 +00:00
}
2022-04-14 01:27:39 +00:00
func (n SimpleItem[any]) Title() string {
2021-12-04 03:42:31 +00:00
return n.ItemTitle
2021-12-02 04:00:33 +00:00
}
2022-04-14 01:27:39 +00:00
func (n SimpleItem[any]) FilterValue() string {
2021-12-04 03:42:31 +00:00
return n.ItemTitle
2021-12-02 04:00:33 +00:00
}
2022-04-14 01:27:39 +00:00
func (n SimpleItem[any]) Description() string {
2021-12-04 03:42:31 +00:00
return ""
2021-12-02 04:00:33 +00:00
}
2021-12-04 03:42:31 +00:00
func NewItemDelegate() list.ItemDelegate {
delegate := list.NewDefaultDelegate()
delegate.ShowDescription = false
delegate.SetSpacing(0)
2021-12-02 04:00:33 +00:00
2021-12-04 03:42:31 +00:00
// TODO Adaptive Colors
// TODO Description Colors
delegate.Styles.NormalTitle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}).
Padding(0, 0, 0, 2)
2021-12-02 04:00:33 +00:00
2021-12-04 03:42:31 +00:00
delegate.Styles.DimmedTitle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}).
Padding(0, 0, 0, 2)
2021-12-02 04:00:33 +00:00
2021-12-04 03:42:31 +00:00
delegate.Styles.SelectedTitle = lipgloss.NewStyle().
Border(lipgloss.ThickBorder(), false, false, false, true).
BorderForeground(lipgloss.Color("202")).
Foreground(lipgloss.Color("202")).
Padding(0, 0, 0, 1)
2021-12-02 04:00:33 +00:00
2021-12-04 03:42:31 +00:00
return delegate
2021-12-02 04:00:33 +00:00
}