Skip to content

Commit

Permalink
refactor: list delegate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jul 21, 2024
1 parent 8e82606 commit 01ae570
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
10 changes: 5 additions & 5 deletions internal/ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func InitialModel(db *sql.DB, config Config) model {
var taskList list.Model
switch config.ListDensity {
case Compact:
taskList = list.New(taskItems, newCompactListDel(lipgloss.Color(config.TaskListColor)), taskSummaryWidth, defaultListHeight)
taskList = list.New(taskItems, newListDelegate(lipgloss.Color(config.TaskListColor), false), taskSummaryWidth, defaultListHeight)
case Spacious:
taskList = list.New(taskItems, newSpaciousListDel(lipgloss.Color(config.TaskListColor)), taskSummaryWidth, defaultListHeight)
taskList = list.New(taskItems, newListDelegate(lipgloss.Color(config.TaskListColor), true), taskSummaryWidth, defaultListHeight)
}
taskList.Title = config.TaskListTitle
taskList.SetFilteringEnabled(true)
Expand All @@ -44,9 +44,9 @@ func InitialModel(db *sql.DB, config Config) model {
var archivedTaskList list.Model
switch config.ListDensity {
case Compact:
archivedTaskList = list.New(archivedTaskItems, newCompactListDel(lipgloss.Color(config.ArchivedTaskListColor)), taskSummaryWidth, defaultListHeight)
archivedTaskList = list.New(archivedTaskItems, newListDelegate(lipgloss.Color(config.ArchivedTaskListColor), false), taskSummaryWidth, defaultListHeight)
case Spacious:
archivedTaskList = list.New(archivedTaskItems, newSpaciousListDel(lipgloss.Color(config.ArchivedTaskListColor)), taskSummaryWidth, defaultListHeight)
archivedTaskList = list.New(archivedTaskItems, newListDelegate(lipgloss.Color(config.ArchivedTaskListColor), true), taskSummaryWidth, defaultListHeight)
}
archivedTaskList.Title = "archived"
archivedTaskList.SetShowStatusBar(true)
Expand All @@ -68,7 +68,7 @@ func InitialModel(db *sql.DB, config Config) model {
taskInput.CharLimit = types.TaskSummaryMaxLen
taskInput.Width = taskSummaryWidth

contextBMList := list.New(nil, newContextURLListDel(contextBMColor), taskSummaryWidth, defaultListHeight)
contextBMList := list.New(nil, newListDelegate(lipgloss.Color(contextBMColor), false), taskSummaryWidth, defaultListHeight)

contextBMList.Title = "task bookmarks"
contextBMList.SetShowHelp(false)
Expand Down
33 changes: 2 additions & 31 deletions internal/ui/list_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@ import (
"github.com/charmbracelet/lipgloss"
)

func newCompactListDel(color lipgloss.Color) list.DefaultDelegate {
func newListDelegate(color lipgloss.Color, showDesc bool) list.DefaultDelegate {
d := list.NewDefaultDelegate()
d.ShowDescription = false
d.SetHeight(1)

d.Styles.SelectedTitle = d.Styles.
SelectedTitle.
Foreground(color).
BorderLeftForeground(color)
d.Styles.FilterMatch = lipgloss.NewStyle()

return d
}

func newSpaciousListDel(color lipgloss.Color) list.DefaultDelegate {
d := list.NewDefaultDelegate()
d.ShowDescription = showDesc

d.Styles.SelectedTitle = d.Styles.
SelectedTitle.
Expand All @@ -34,20 +22,3 @@ func newSpaciousListDel(color lipgloss.Color) list.DefaultDelegate {

return d
}

func newContextURLListDel(color lipgloss.Color) list.DefaultDelegate {
d := list.NewDefaultDelegate()
d.SetSpacing(1)
d.ShowDescription = false
d.SetHeight(1)

d.Styles.SelectedTitle = d.Styles.
SelectedTitle.
Foreground(color).
BorderLeftForeground(color)

d.Styles.SelectedDesc = d.Styles.
SelectedTitle

return d
}
8 changes: 4 additions & 4 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch m.cfg.ListDensity {
case Compact:
tlDel = newSpaciousListDel(lipgloss.Color(m.cfg.TaskListColor))
atlDel = newSpaciousListDel(lipgloss.Color(m.cfg.ArchivedTaskListColor))
tlDel = newListDelegate(lipgloss.Color(m.cfg.TaskListColor), true)
atlDel = newListDelegate(lipgloss.Color(m.cfg.ArchivedTaskListColor), true)

m.cfg.ListDensity = Spacious

case Spacious:
tlDel = newCompactListDel(lipgloss.Color(m.cfg.TaskListColor))
atlDel = newCompactListDel(lipgloss.Color(m.cfg.ArchivedTaskListColor))
tlDel = newListDelegate(lipgloss.Color(m.cfg.TaskListColor), false)
atlDel = newListDelegate(lipgloss.Color(m.cfg.ArchivedTaskListColor), false)
m.cfg.ListDensity = Compact
}

Expand Down

0 comments on commit 01ae570

Please sign in to comment.