diff --git a/internal/model/simplelist/list.go b/internal/model/simplelist/list.go index 70cf11b..b2d4171 100644 --- a/internal/model/simplelist/list.go +++ b/internal/model/simplelist/list.go @@ -14,13 +14,11 @@ import ( // Model contains state of the list type Model struct { - title string - height int - items []list.Item - selected int - titleStyle lipgloss.Style - noItemsStyle lipgloss.Style - itemStyle lipgloss.Style + title string + height int + items []list.Item + selected int + style listStyle } // New creates a new list @@ -28,18 +26,7 @@ func New(title string, height int) Model { return Model{ title: title, height: height, - titleStyle: lipgloss.NewStyle(). - Foreground(style.GlobalColorscheme.Color1). - MarginLeft(3). - PaddingBottom(1), - noItemsStyle: lipgloss.NewStyle(). - MarginLeft(3). - Foreground(style.GlobalColorscheme.Color2). - Italic(true), - itemStyle: lipgloss.NewStyle(). - MarginLeft(3). - MarginRight(3). - Foreground(style.GlobalColorscheme.Color2), + style: newDefaultListStyle(), } } @@ -76,11 +63,11 @@ func (m Model) View() string { sections := make([]string, 1) // Create the title - sections = append(sections, m.titleStyle.Render(m.title)) + sections = append(sections, m.style.titleStyle.Render(m.title)) // If the list is empty show a message if len(m.items) == 0 { - sections = append(sections, m.noItemsStyle.Render("")) + sections = append(sections, m.style.noItemsStyle.Render("")) return lipgloss.JoinVertical(lipgloss.Top, sections...) } @@ -88,7 +75,7 @@ func (m Model) View() string { for i, item := range m.items { isSelected := i == m.selected itemText := fmt.Sprintf("%s %s", style.Index(i, isSelected), item.FilterValue()) - itemLine := m.itemStyle.Render(itemText) + itemLine := m.style.itemStyle.Render(itemText) sections = append(sections, itemLine) } diff --git a/internal/model/simplelist/style.go b/internal/model/simplelist/style.go new file mode 100644 index 0000000..2b2e512 --- /dev/null +++ b/internal/model/simplelist/style.go @@ -0,0 +1,40 @@ +package simplelist + +import ( + "github.com/TypicalAM/goread/internal/style" + "github.com/charmbracelet/lipgloss" +) + +// listStyle is the style of the list. +type listStyle struct { + titleStyle lipgloss.Style + noItemsStyle lipgloss.Style + itemStyle lipgloss.Style +} + +// newDefaultListStyle returns a new list style with default values. +func newDefaultListStyle() listStyle { + // Create the new style + newStyle := listStyle{} + + // titleStyle is used to style the title of the list + newStyle.titleStyle = lipgloss.NewStyle(). + Foreground(style.GlobalColorscheme.Color1). + MarginLeft(3). + PaddingBottom(1) + + // newItemsStyle is used to style the message when there are no items + newStyle.noItemsStyle = lipgloss.NewStyle(). + MarginLeft(3). + Foreground(style.GlobalColorscheme.Color2). + Italic(true) + + // newItemsStyle is used to style the items in the list + newStyle.itemStyle = lipgloss.NewStyle(). + MarginLeft(3). + MarginRight(3). + Foreground(style.GlobalColorscheme.Color2) + + // Return the new style + return newStyle +}