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

58 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"
)
2021-12-04 03:42:31 +00:00
var _ list.DefaultItem = (*SimpleItem)(nil)
2021-12-02 04:00:33 +00:00
type SimpleItem struct {
2021-12-04 03:42:31 +00:00
ItemTitle string
Activate func(msg tea.Msg, currentModel tea.Model) (tea.Model, tea.Cmd)
// I know this is ugly but generics are coming soon and I cba
Extra interface{}
}
func (n SimpleItem) Title() string {
return n.ItemTitle
2021-12-02 04:00:33 +00:00
}
func (n SimpleItem) FilterValue() string {
2021-12-04 03:42:31 +00:00
return n.ItemTitle
2021-12-02 04:00:33 +00:00
}
func (n SimpleItem) GetTitle() string {
2021-12-04 03:42:31 +00:00
return n.ItemTitle
2021-12-02 04:00:33 +00:00
}
2021-12-04 03:42:31 +00:00
func (n SimpleItem) Description() string {
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
}