refactor: use KeyPressMsg and MouseClickMsg instead of KeyMsg and MouseMsg

Ayman Bagabas created

Change summary

cmd/soft/browse/browse.go              |  2 
pkg/ssh/ui.go                          | 55 +++++++++++++--------------
pkg/ui/components/selector/selector.go |  2 
pkg/ui/components/tabs/tabs.go         |  2 
pkg/ui/components/viewport/viewport.go |  2 
pkg/ui/pages/repo/files.go             |  2 
pkg/ui/pages/repo/filesitem.go         |  2 
pkg/ui/pages/repo/log.go               |  6 +-
pkg/ui/pages/repo/logitem.go           |  2 
pkg/ui/pages/repo/refs.go              |  2 
pkg/ui/pages/repo/refsitem.go          |  2 
pkg/ui/pages/repo/repo.go              |  6 +-
pkg/ui/pages/repo/stash.go             |  2 
pkg/ui/pages/repo/stashitem.go         |  2 
pkg/ui/pages/selection/item.go         |  2 
pkg/ui/pages/selection/selection.go    |  4 +-
16 files changed, 46 insertions(+), 49 deletions(-)

Detailed changes

cmd/soft/browse/browse.go 🔗

@@ -151,7 +151,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	switch msg := msg.(type) {
 	case tea.WindowSizeMsg:
 		m.SetSize(msg.Width, msg.Height)
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, m.common.KeyMap.Back) && m.error != nil:
 			m.error = nil

pkg/ssh/ui.go 🔗

@@ -179,37 +179,34 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				cmds = append(cmds, cmd)
 			}
 		}
-	case tea.KeyMsg, tea.MouseMsg:
-		switch msg := msg.(type) {
-		case tea.KeyMsg:
+	case tea.KeyPressMsg:
+		switch {
+		case key.Matches(msg, ui.common.KeyMap.Back) && ui.error != nil:
+			ui.error = nil
+			ui.state = readyState
+			// Always show the footer on error.
+			ui.showFooter = ui.footer.ShowAll()
+		case key.Matches(msg, ui.common.KeyMap.Help):
+			cmds = append(cmds, footer.ToggleFooterCmd)
+		case key.Matches(msg, ui.common.KeyMap.Quit):
+			if !ui.IsFiltering() {
+				// Stop bubblezone background workers.
+				ui.common.Zone.Close()
+				return ui, tea.Quit
+			}
+		case ui.activePage == repoPage &&
+			ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
+			key.Matches(msg, ui.common.KeyMap.Back):
+			ui.activePage = selectionPage
+			// Always show the footer on selection page.
+			ui.showFooter = true
+		}
+	case tea.MouseClickMsg:
+		switch msg.Mouse().Button {
+		case tea.MouseLeft:
 			switch {
-			case key.Matches(msg, ui.common.KeyMap.Back) && ui.error != nil:
-				ui.error = nil
-				ui.state = readyState
-				// Always show the footer on error.
-				ui.showFooter = ui.footer.ShowAll()
-			case key.Matches(msg, ui.common.KeyMap.Help):
+			case ui.common.Zone.Get("footer").InBounds(msg):
 				cmds = append(cmds, footer.ToggleFooterCmd)
-			case key.Matches(msg, ui.common.KeyMap.Quit):
-				if !ui.IsFiltering() {
-					// Stop bubblezone background workers.
-					ui.common.Zone.Close()
-					return ui, tea.Quit
-				}
-			case ui.activePage == repoPage &&
-				ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
-				key.Matches(msg, ui.common.KeyMap.Back):
-				ui.activePage = selectionPage
-				// Always show the footer on selection page.
-				ui.showFooter = true
-			}
-		case tea.MouseClickMsg:
-			switch msg.Mouse().Button {
-			case tea.MouseLeft:
-				switch {
-				case ui.common.Zone.Get("footer").InBounds(msg):
-					cmds = append(cmds, footer.ToggleFooterCmd)
-				}
 			}
 		}
 	case footer.ToggleFooterMsg:

pkg/ui/components/selector/selector.go 🔗

@@ -252,7 +252,7 @@ func (s *Selector) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				}
 			}
 		}
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		filterState := s.FilterState()
 		switch {
 		case key.Matches(msg, s.common.KeyMap.Help):

pkg/ui/components/tabs/tabs.go 🔗

@@ -54,7 +54,7 @@ func (t *Tabs) Init() tea.Cmd {
 func (t *Tabs) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	cmds := make([]tea.Cmd, 0)
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch msg.String() {
 		case "tab":
 			t.activeTab = (t.activeTab + 1) % len(t.tabs)

pkg/ui/components/viewport/viewport.go 🔗

@@ -40,7 +40,7 @@ func (v *Viewport) Init() tea.Cmd {
 // Update implements tea.Model.
 func (v *Viewport) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, v.common.KeyMap.GotoTop):
 			v.GotoTop()

pkg/ui/pages/repo/files.go 🔗

@@ -264,7 +264,7 @@ func (f *Files) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		case filesViewFiles, filesViewContent:
 			cmds = append(cmds, f.deselectItemCmd())
 		}
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch f.activeView {
 		case filesViewFiles:
 			switch {

pkg/ui/pages/repo/filesitem.go 🔗

@@ -82,7 +82,7 @@ func (d FileItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 		return nil
 	}
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, d.common.KeyMap.Copy):
 			return copyCmd(item.entry.Name(), fmt.Sprintf("File name %q copied to clipboard", item.entry.Name()))

pkg/ui/pages/repo/log.go 🔗

@@ -221,11 +221,11 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		if i != nil {
 			l.activeCommit = i.(LogItem).Commit
 		}
-	case tea.KeyMsg, tea.MouseMsg:
+	case tea.KeyPressMsg, tea.MouseClickMsg:
 		switch l.activeView {
 		case logViewCommits:
 			switch kmsg := msg.(type) {
-			case tea.KeyMsg:
+			case tea.KeyPressMsg:
 				switch {
 				case key.Matches(kmsg, l.common.KeyMap.SelectItem):
 					cmds = append(cmds, l.selector.SelectItemCmd)
@@ -248,7 +248,7 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			cmds = append(cmds, cmd)
 		case logViewDiff:
 			switch kmsg := msg.(type) {
-			case tea.KeyMsg:
+			case tea.KeyPressMsg:
 				switch {
 				case key.Matches(kmsg, l.common.KeyMap.BackItem):
 					l.goBack()

pkg/ui/pages/repo/logitem.go 🔗

@@ -62,7 +62,7 @@ func (d LogItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 		return nil
 	}
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, d.common.KeyMap.Copy):
 			return copyCmd(item.Hash(), "Commit hash copied to clipboard")

pkg/ui/pages/repo/refs.go 🔗

@@ -152,7 +152,7 @@ func (r *Refs) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				switchTabCmd(&Files{}),
 			)
 		}
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, r.common.KeyMap.SelectItem):
 			cmds = append(cmds, r.selector.SelectItemCmd)

pkg/ui/pages/repo/refsitem.go 🔗

@@ -83,7 +83,7 @@ func (d RefItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 		return nil
 	}
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, d.common.KeyMap.Copy):
 			return copyCmd(item.ID(), fmt.Sprintf("Reference %q copied to clipboard", item.ID()))

pkg/ui/pages/repo/repo.go 🔗

@@ -171,7 +171,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		}
 	case tabs.ActiveTabMsg:
 		r.activeTab = int(msg)
-	case tea.KeyMsg, tea.MouseMsg:
+	case tea.KeyPressMsg, tea.MouseClickMsg:
 		t, cmd := r.tabs.Update(msg)
 		r.tabs = t.(*tabs.Tabs)
 		if cmd != nil {
@@ -200,7 +200,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			}
 		}
 		switch msg := msg.(type) {
-		case tea.KeyMsg:
+		case tea.KeyPressMsg:
 			switch {
 			case key.Matches(msg, r.common.KeyMap.Back):
 				cmds = append(cmds, goBackCmd)
@@ -271,7 +271,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	// Update the status bar on these events
 	// Must come after we've updated the active tab
 	switch msg.(type) {
-	case RepoMsg, RefMsg, tabs.ActiveTabMsg, tea.KeyMsg, tea.MouseMsg,
+	case RepoMsg, RefMsg, tabs.ActiveTabMsg, tea.KeyPressMsg, tea.MouseClickMsg,
 		FileItemsMsg, FileContentMsg, FileBlameMsg, selector.ActiveMsg,
 		LogItemsMsg, GoBackMsg, LogDiffMsg, EmptyRepoMsg,
 		StashListMsg, StashPatchMsg:

pkg/ui/pages/repo/stash.go 🔗

@@ -165,7 +165,7 @@ func (s *Stash) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				cmds = append(cmds, cmd)
 			}
 		}
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch s.state {
 		case stashStateList:
 			switch {

pkg/ui/pages/repo/stashitem.go 🔗

@@ -65,7 +65,7 @@ func (d StashItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 	}
 
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, d.common.KeyMap.Copy):
 			return copyCmd(item.Title(), fmt.Sprintf("Stash message %q copied to clipboard", item.Title()))

pkg/ui/pages/selection/item.go 🔗

@@ -135,7 +135,7 @@ func (d *ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 		return nil
 	}
 	switch msg := msg.(type) {
-	case tea.KeyMsg:
+	case tea.KeyPressMsg:
 		switch {
 		case key.Matches(msg, d.common.KeyMap.Copy):
 			d.copiedIdx = idx

pkg/ui/pages/selection/selection.go 🔗

@@ -250,9 +250,9 @@ func (s *Selection) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		if cmd != nil {
 			cmds = append(cmds, cmd)
 		}
-	case tea.KeyMsg, tea.MouseMsg:
+	case tea.KeyPressMsg, tea.MouseMsg:
 		switch msg := msg.(type) {
-		case tea.KeyMsg:
+		case tea.KeyPressMsg:
 			switch {
 			case key.Matches(msg, s.common.KeyMap.Back):
 				cmds = append(cmds, s.selector.Init())