diff --git a/go.sum b/go.sum index 1a86d856303c73a8dd790b997bc599cdb8dd3335..253ee4e7e0d6f2e76dbb38300517f0495b36e028 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,6 @@ github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k github.com/caarlos0/env/v6 v6.9.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= github.com/caarlos0/sshmarshal v0.0.0-20220308164159-9ddb9f83c6b3 h1:w2ANoiT4ubmh4Nssa3/QW1M7lj3FZkma8f8V5aBDxXM= github.com/caarlos0/sshmarshal v0.0.0-20220308164159-9ddb9f83c6b3/go.mod h1:7Pd/0mmq9x/JCzKauogNjSQEhivBclCQHfr9dlpDIyA= -github.com/charmbracelet/bubbles v0.10.4-0.20220429162018-2a8d463bd11f h1:5mbyuBNzjF1S1pJOGubmjMBNUVO3NmjNsaZPIsFwPUQ= -github.com/charmbracelet/bubbles v0.10.4-0.20220429162018-2a8d463bd11f/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA= github.com/charmbracelet/bubbles v0.10.4-0.20220524120539-e1871db6d35e h1:B+COqRjrl6G/X6v7salT4LDoSl+2Kz3g4OuDaoZCMwA= github.com/charmbracelet/bubbles v0.10.4-0.20220524120539-e1871db6d35e/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA= github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA= diff --git a/ui/common/component.go b/ui/common/component.go index 2880f30e41717ba661e5f09d6230e29843e6e661..ed8b9bf05cd39b52086a2a490b045231ac1fd96e 100644 --- a/ui/common/component.go +++ b/ui/common/component.go @@ -8,11 +8,6 @@ import ( // Component represents a Bubble Tea model that implements a SetSize function. type Component interface { tea.Model - SetSize(width, height int) -} - -// Page represents a component that implements help.KeyMap. -type Page interface { - Component help.KeyMap + SetSize(width, height int) } diff --git a/ui/pages/repo/repo.go b/ui/pages/repo/repo.go index fa779926d166cfac0a53198237b2884b6356b30a..71ba68cfa876b698969b1a50b4f9873cd09858ba 100644 --- a/ui/pages/repo/repo.go +++ b/ui/pages/repo/repo.go @@ -24,8 +24,19 @@ const ( commitsTab branchesTab tagsTab + lastTab ) +func (t tab) String() string { + return []string{ + "Readme", + "Files", + "Commits", + "Branches", + "Tags", + }[t] +} + // UpdateStatusBarMsg updates the status bar. type UpdateStatusBarMsg struct{} @@ -51,8 +62,12 @@ type Repo struct { // New returns a new Repo. func New(cfg *config.Config, rs git.GitRepoSource, c common.Common) *Repo { sb := statusbar.New(c) + ts := make([]string, lastTab) // Tabs must match the order of tab constants above. - tb := tabs.New(c, []string{"Readme", "Files", "Commits", "Branches", "Tags"}) + for i, t := range []tab{readmeTab, filesTab, commitsTab, branchesTab, tagsTab} { + ts[i] = t.String() + } + tb := tabs.New(c, ts) readme := NewReadme(c) log := NewLog(c) files := NewFiles(c) diff --git a/ui/pages/selection/selection.go b/ui/pages/selection/selection.go index 4eb83369ce5084dd2f59da0b559089c247d85d41..0afd330524ef25afee85aa1e649dd0c2b4b869f7 100644 --- a/ui/pages/selection/selection.go +++ b/ui/pages/selection/selection.go @@ -20,10 +20,18 @@ import ( type box int const ( - readmeBox box = iota - selectorBox + selectorBox box = iota + readmeBox + lastBox ) +func (b box) String() string { + return []string{ + "Repositories", + "About", + }[b] +} + // Selection is the model for the selection screen/page. type Selection struct { cfg *config.Config @@ -38,7 +46,11 @@ type Selection struct { // New creates a new selection model. func New(cfg *config.Config, pk ssh.PublicKey, common common.Common) *Selection { - t := tabs.New(common, []string{"About", "Repositories"}) + ts := make([]string, lastBox) + for i, b := range []box{selectorBox, readmeBox} { + ts[i] = b.String() + } + t := tabs.New(common, ts) t.TabSeparator = lipgloss.NewStyle() t.TabInactive = lipgloss.NewStyle(). Bold(true). @@ -52,7 +64,7 @@ func New(cfg *config.Config, pk ssh.PublicKey, common common.Common) *Selection cfg: cfg, pk: pk, common: common, - activeBox: readmeBox, // start with the selector focused + activeBox: selectorBox, // start with the selector focused tabs: t, } readme := code.New(common, "", "") diff --git a/ui/ui.go b/ui/ui.go index 34e735d06bfebfd1b841bfec196c29313cf311d8..3992f0fb4851389960392cbe50e4e7a90ef4efa7 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -40,7 +40,7 @@ type UI struct { rs git.GitRepoSource initialRepo string common common.Common - pages []common.Page + pages []common.Component activePage page state sessionState header *header.Header @@ -57,7 +57,7 @@ func New(cfg *config.Config, s ssh.Session, c common.Common, initialRepo string) session: s, rs: src, common: c, - pages: make([]common.Page, 2), // selection & repo + pages: make([]common.Component, 2), // selection & repo activePage: selectionPage, state: startState, header: h, @@ -163,7 +163,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ui.SetSize(msg.Width, msg.Height) for i, p := range ui.pages { m, cmd := p.Update(msg) - ui.pages[i] = m.(common.Page) + ui.pages[i] = m.(common.Component) if cmd != nil { cmds = append(cmds, cmd) } @@ -183,6 +183,8 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ui.activePage = selectionPage } } + case repo.RepoMsg: + ui.activePage = repoPage case common.ErrorMsg: ui.error = msg ui.state = errorState @@ -207,7 +209,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } if ui.state == loadedState { m, cmd := ui.pages[ui.activePage].Update(msg) - ui.pages[ui.activePage] = m.(common.Page) + ui.pages[ui.activePage] = m.(common.Component) if cmd != nil { cmds = append(cmds, cmd) } @@ -262,7 +264,6 @@ func (ui *UI) setRepoCmd(rn string) tea.Cmd { return func() tea.Msg { for _, r := range ui.rs.AllRepos() { if r.Repo() == rn { - ui.activePage = repoPage return repo.RepoMsg(r) } } @@ -274,7 +275,6 @@ func (ui *UI) initialRepoCmd(rn string) tea.Cmd { return func() tea.Msg { for _, r := range ui.rs.AllRepos() { if r.Repo() == rn { - ui.activePage = repoPage return repo.RepoMsg(r) } }