wip: add selector mouse wheel support

Ayman Bagabas created

Change summary

go.mod                             |  2 +-
go.sum                             |  2 ++
ui/components/selector/selector.go |  7 +++++++
ui/pages/selection/selection.go    | 22 +++++++++++++++-------
4 files changed, 25 insertions(+), 8 deletions(-)

Detailed changes

go.mod 🔗

@@ -22,7 +22,7 @@ require (
 )
 
 require (
-	github.com/aymanbagabas/go-osc52 v1.0.1
+	github.com/aymanbagabas/go-osc52 v1.0.2
 	github.com/charmbracelet/keygen v0.3.0
 	github.com/gobwas/glob v0.2.3
 	github.com/gogs/git-module v1.6.0

go.sum 🔗

@@ -19,6 +19,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
 github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
 github.com/aymanbagabas/go-osc52 v1.0.1 h1:juDXgeKhMfVnylcoA4S7p9E4q+9DErUZGkX8t2ZR2j8=
 github.com/aymanbagabas/go-osc52 v1.0.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
+github.com/aymanbagabas/go-osc52 v1.0.2 h1:tRqcFxSpoDFwHzgjjgU3rACsQHmKo7w7EJf+oCEFI6k=
+github.com/aymanbagabas/go-osc52 v1.0.2/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
 github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
 github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
 github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k=

ui/components/selector/selector.go 🔗

@@ -76,6 +76,13 @@ func (s *Selector) Init() tea.Cmd {
 func (s *Selector) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	cmds := make([]tea.Cmd, 0)
 	switch msg := msg.(type) {
+	case tea.MouseMsg:
+		switch msg.Type {
+		case tea.MouseWheelUp:
+			s.list.CursorUp()
+		case tea.MouseWheelDown:
+			s.list.CursorDown()
+		}
 	case tea.KeyMsg:
 		switch {
 		case key.Matches(msg, s.common.Keymap.Select):

ui/pages/selection/selection.go 🔗

@@ -3,7 +3,6 @@ package selection
 import (
 	"fmt"
 	"strings"
-	"time"
 
 	"github.com/charmbracelet/bubbles/key"
 	"github.com/charmbracelet/bubbles/list"
@@ -140,19 +139,28 @@ func (s *Selection) Init() tea.Cmd {
 	// Put configured repos first
 	for _, r := range cfg.Repos {
 		items = append(items, Item{
-			name:       r.Name,
-			repo:       r.Repo,
-			desc:       r.Note,
-			lastUpdate: time.Now(), // TODO get repo last update
-			url:        yank(repoUrl(cfg, r.Repo)),
+			name: r.Name,
+			repo: r.Repo,
+			desc: r.Note,
+			url:  yank(repoUrl(cfg, r.Repo)),
 		})
 	}
 	for _, r := range cfg.Source.AllRepos() {
 		exists := false
+		head, err := r.HEAD()
+		if err != nil {
+			return common.ErrorCmd(err)
+		}
+		lc, err := r.CommitsByPage(head, 1, 1)
+		if err != nil {
+			return common.ErrorCmd(err)
+		}
+		lastUpdate := lc[0].Committer.When
 		for _, item := range items {
 			item := item.(Item)
 			if item.repo == r.Name() {
 				exists = true
+				item.lastUpdate = lastUpdate
 				break
 			}
 		}
@@ -161,7 +169,7 @@ func (s *Selection) Init() tea.Cmd {
 				name:       r.Name(),
 				repo:       r.Name(),
 				desc:       "",
-				lastUpdate: time.Now(), // TODO get repo last update
+				lastUpdate: lastUpdate,
 				url:        yank(repoUrl(cfg, r.Name())),
 			})
 		}