chore(list): fix v2 errors

This commit is contained in:
Christian Rocha
2024-10-23 22:10:46 -04:00
parent 89f2eef648
commit c0611f6c76
4 changed files with 98 additions and 58 deletions
+39 -18
View File
@@ -30,37 +30,58 @@ type DefaultItemStyles struct {
FilterMatch lipgloss.Style
}
// NewDefaultItemStyles returns style definitions for a default item. See
// DefaultItemView for when these come into play.
func NewDefaultItemStyles() (s DefaultItemStyles) {
// BaseItemStyles returns a set of base styles for a default item. No color
// will be applied. You can use this as a starting point for your own styles,
// if you like.
func BaseItemStyles() (s DefaultItemStyles) {
s.NormalTitle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}).
Padding(0, 0, 0, 2)
s.NormalDesc = s.NormalTitle.
Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"})
s.NormalDesc = s.NormalTitle
s.SelectedTitle = lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), false, false, false, true).
BorderForeground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}).
Foreground(lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"}).
Padding(0, 0, 0, 1)
s.SelectedDesc = s.SelectedTitle.
Foreground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"})
s.SelectedDesc = s.SelectedTitle
s.DimmedTitle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}).
Padding(0, 0, 0, 2)
s.DimmedDesc = s.DimmedTitle
s.FilterMatch = lipgloss.NewStyle().
Underline(true)
return s
}
s.DimmedDesc = s.DimmedTitle.
Foreground(lipgloss.AdaptiveColor{Light: "#C2B8C2", Dark: "#4D4D4D"})
func newItemStyles(isDark bool) DefaultItemStyles {
lightDark := lipgloss.LightDark(isDark)
s := BaseItemStyles()
s.FilterMatch = lipgloss.NewStyle().Underline(true)
s.NormalTitle = s.NormalTitle.
Foreground(lightDark("#1a1a1a", "#dddddd"))
s.NormalDesc = s.NormalDesc.
Foreground(lightDark("#A49FA5", "#777777"))
s.SelectedTitle = s.SelectedTitle.
BorderForeground(lightDark("#F793FF", "#AD58B4")).
Foreground(lightDark("#EE6FF8", "#EE6FF8"))
s.SelectedDesc = s.SelectedDesc.
Foreground(lightDark("#F793FF", "#AD58B4"))
s.DimmedTitle = s.DimmedTitle.
Foreground(lightDark("#A49FA5", "#777777"))
s.DimmedDesc = s.DimmedDesc.
Foreground(lightDark("#C2B8C2", "#4D4D4D"))
return s
}
// NewDefaultItemStyles returns light style definitions for a default item. See
// [DefaultItemView] for when these come into play.
func NewLightItemStyles() DefaultItemStyles {
return newItemStyles(false)
}
// NewDefaultItemStyles returns default dark style definitions for a default
// item. See [DefaultItemView] for when these come into play.
func NewDefaultItemStyles() DefaultItemStyles {
return newItemStyles(true)
}
// DefaultItem describes an item designed to work with DefaultDelegate.
type DefaultItem interface {
Item
+2 -2
View File
@@ -205,7 +205,7 @@ func New(items []Item, delegate ItemDelegate, width, height int) Model {
filterInput := textinput.New()
filterInput.Prompt = "Filter: "
filterInput.PromptStyle = styles.FilterPrompt
filterInput.Styles.Focused.Prompt = styles.FilterPrompt
filterInput.Cursor.Style = styles.FilterCursor
filterInput.CharLimit = 64
filterInput.Focus()
@@ -689,7 +689,7 @@ func (m *Model) setSize(width, height int) {
m.width = width
m.height = height
m.Help.Width = width
m.FilterInput.Width = width - promptWidth - lipgloss.Width(m.spinnerView())
m.FilterInput.SetWidth(width - promptWidth - lipgloss.Width(m.spinnerView()))
m.updatePagination()
}
+56 -37
View File
@@ -39,6 +39,42 @@ type Styles struct {
DividerDot lipgloss.Style
}
// BaseStyles returns a set of base styles for this list component. No color
// will be applied. You can use this as a starting point for your own styles,
// if you like.
func BaseStyles() Styles {
var s Styles
s.TitleBar = lipgloss.NewStyle().
Padding(0, 0, 1, 2)
s.Title = lipgloss.NewStyle().
Padding(0, 1)
s.Spinner = lipgloss.NewStyle()
s.FilterPrompt = lipgloss.NewStyle()
s.FilterCursor = lipgloss.NewStyle()
s.DefaultFilterCharacterMatch = lipgloss.NewStyle().
Underline(true)
s.StatusBar = lipgloss.NewStyle().
Padding(0, 0, 1, 2)
s.StatusEmpty = lipgloss.NewStyle()
s.StatusBarActiveFilter = lipgloss.NewStyle()
s.StatusBarFilterCount = lipgloss.NewStyle()
s.NoItems = lipgloss.NewStyle()
s.ArabicPagination = lipgloss.NewStyle()
s.PaginationStyle = lipgloss.NewStyle().
PaddingLeft(2) //nolint:gomnd
s.HelpStyle = lipgloss.NewStyle().
Padding(1, 0, 0, 2)
s.ActivePaginationDot = lipgloss.NewStyle().
SetString(bullet)
s.InactivePaginationDot = lipgloss.NewStyle().
SetString(bullet)
s.DividerDot = lipgloss.NewStyle().
SetString(" " + bullet + " ")
return s
}
// LightStyles returns a set of light style definitions for this list Bubble.
func LightStyles() Styles {
return newStyles(false)
@@ -57,53 +93,36 @@ func newStyles(isDark bool) (s Styles) {
verySubduedColor := lightDark("#DDDADA", "#3C3C3C")
subduedColor := lightDark("#9B9B9B", "#5C5C5C")
s.TitleBar = lipgloss.NewStyle().Padding(0, 0, 1, 2)
s.Title = lipgloss.NewStyle().
s.Title = s.Title.
Background(lipgloss.Color("62")).
Foreground(lipgloss.Color("230")).
Padding(0, 1)
s.Spinner = lipgloss.NewStyle().
Foreground(lipgloss.Color("230"))
s.Spinner = s.Spinner.
Foreground(lightDark("#8E8E8E", "#747373"))
s.FilterPrompt = lipgloss.NewStyle().
s.FilterPrompt = s.FilterPrompt.
Foreground(lightDark("#04B575", "#ECFD65"))
s.FilterCursor = lipgloss.NewStyle().
s.FilterCursor = s.FilterCursor.
Foreground(lightDark("#EE6FF8", "#EE6FF8"))
s.DefaultFilterCharacterMatch = lipgloss.NewStyle().Underline(true)
s.StatusBar = lipgloss.NewStyle().
Foreground(lightDark("#A49FA5", "#777777")).
Padding(0, 0, 1, 2)
s.StatusEmpty = lipgloss.NewStyle().Foreground(subduedColor)
s.StatusBarActiveFilter = lipgloss.NewStyle().
s.StatusBar = s.StatusBar.
Foreground(lightDark("#A49FA5", "#777777"))
s.StatusEmpty = s.StatusEmpty.
Foreground(subduedColor)
s.StatusBarActiveFilter = s.StatusBarActiveFilter.
Foreground(lightDark("#1a1a1a", "#dddddd"))
s.StatusBarFilterCount = lipgloss.NewStyle().Foreground(verySubduedColor)
s.NoItems = lipgloss.NewStyle().
s.StatusBarFilterCount = s.StatusBarFilterCount.
Foreground(verySubduedColor)
s.NoItems = s.NoItems.
Foreground(lightDark("#909090", "#626262"))
s.ArabicPagination = lipgloss.NewStyle().Foreground(subduedColor)
s.PaginationStyle = lipgloss.NewStyle().PaddingLeft(2) //nolint:gomnd
s.HelpStyle = lipgloss.NewStyle().Padding(1, 0, 0, 2)
s.ActivePaginationDot = lipgloss.NewStyle().
s.ArabicPagination = s.ArabicPagination.
Foreground(subduedColor)
s.HelpStyle = s.HelpStyle.
Padding(1, 0, 0, 2)
s.ActivePaginationDot = s.ActivePaginationDot.
Foreground(lightDark("#847A85", "#979797")).
SetString(bullet)
s.InactivePaginationDot = lipgloss.NewStyle().
s.InactivePaginationDot = s.InactivePaginationDot.
Foreground(verySubduedColor).
SetString(bullet)
s.DividerDot = lipgloss.NewStyle().
s.DividerDot = s.DividerDot.
Foreground(verySubduedColor).
SetString(" " + bullet + " ")
+1 -1
View File
@@ -43,7 +43,7 @@ func TestGradient(t *testing.T) {
expLast := strings.Split(sb.String(), AnsiReset)[0]
for _, width := range []int{3, 5, 50} {
p.Width = width
p.SetWidth(width)
res := p.ViewAs(1.0)
// extract colors from the progrss bar by splitting at p.Full+AnsiReset, leaving us with just the color sequences