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