Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
add item delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 5, 2022
1 parent 735f547 commit d21eac5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions tui/item_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ import (
"io"
)

type itemDelegate struct {
type groupItemDelegate struct {
}

func (d itemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
str := fmt.Sprintf("%d. %s", index+1, item.FilterValue())
fmt.Fprint(w, str)
func (d groupItemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
var str string
if m.Index() == index {
str = fmt.Sprintf("> %d. %s", index+1, item.FilterValue())
} else {
str = fmt.Sprintf(" %d. %s", index+1, item.FilterValue())
}
_, _ = fmt.Fprint(w, str)
}

func (d itemDelegate) Height() int {
func (d groupItemDelegate) Height() int {
return 1
}

func (d itemDelegate) Spacing() int {
func (d groupItemDelegate) Spacing() int {
return 0
}

func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
func (d groupItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
return nil
}
2 changes: 1 addition & 1 deletion tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewModel() (*Model, error) {
groups := wrapListItems(groupService.Tree())

// Create group list view
groupList := list.New(groups, list.NewDefaultDelegate(), 0, 0)
groupList := list.New(groups, groupItemDelegate{}, 0, 0)
// TODO add remaining help key
groupList.Title = "Groups"
groupList.SetShowHelp(false)
Expand Down

0 comments on commit d21eac5

Please sign in to comment.