Detailed changes
@@ -7,12 +7,12 @@ import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/charmbracelet/soft-serve/config"
ggit "github.com/charmbracelet/soft-serve/git"
"github.com/charmbracelet/soft-serve/ui/common"
"github.com/charmbracelet/soft-serve/ui/components/statusbar"
"github.com/charmbracelet/soft-serve/ui/components/tabs"
"github.com/charmbracelet/soft-serve/ui/git"
- "github.com/charmbracelet/soft-serve/ui/session"
)
type tab int
@@ -36,8 +36,8 @@ type RefMsg *ggit.Reference
// Repo is a view for a git repository.
type Repo struct {
- s session.Session
common common.Common
+ cfg *config.Config
rs git.GitRepoSource
selectedRepo git.GitRepo
activeTab tab
@@ -48,7 +48,7 @@ type Repo struct {
}
// New returns a new Repo.
-func New(s session.Session, c common.Common) *Repo {
+func New(cfg *config.Config, rs git.GitRepoSource, c common.Common) *Repo {
sb := statusbar.New(c)
// Tabs must match the order of tab constants above.
tb := tabs.New(c, []string{"Readme", "Files", "Commits", "Branches", "Tags"})
@@ -66,9 +66,9 @@ func New(s session.Session, c common.Common) *Repo {
tags,
}
r := &Repo{
- s: s,
+ cfg: cfg,
common: c,
- rs: s.Source(),
+ rs: rs,
tabs: tb,
statusbar: sb,
boxes: boxes,
@@ -241,7 +241,7 @@ func (r *Repo) headerView() string {
if r.selectedRepo == nil {
return ""
}
- cfg := r.s.Config()
+ cfg := r.cfg
name := r.common.Styles.RepoHeaderName.Render(r.selectedRepo.Name())
url := git.RepoURL(cfg.Host, cfg.Port, r.selectedRepo.Repo())
// TODO move this into a style.
@@ -6,12 +6,13 @@ import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/charmbracelet/soft-serve/config"
"github.com/charmbracelet/soft-serve/ui/common"
"github.com/charmbracelet/soft-serve/ui/components/code"
"github.com/charmbracelet/soft-serve/ui/components/selector"
"github.com/charmbracelet/soft-serve/ui/git"
- "github.com/charmbracelet/soft-serve/ui/session"
wgit "github.com/charmbracelet/wish/git"
+ "github.com/gliderlabs/ssh"
)
type box int
@@ -23,7 +24,8 @@ const (
// Selection is the model for the selection screen/page.
type Selection struct {
- s session.Session
+ cfg *config.Config
+ pk ssh.PublicKey
common common.Common
readme *code.Code
readmeHeight int
@@ -32,9 +34,10 @@ type Selection struct {
}
// New creates a new selection model.
-func New(s session.Session, common common.Common) *Selection {
+func New(cfg *config.Config, pk ssh.PublicKey, common common.Common) *Selection {
sel := &Selection{
- s: s,
+ cfg: cfg,
+ pk: pk,
common: common,
activeBox: selectorBox, // start with the selector focused
}
@@ -152,8 +155,8 @@ func (s *Selection) FullHelp() [][]key.Binding {
func (s *Selection) Init() tea.Cmd {
var readmeCmd tea.Cmd
items := make([]selector.IdentifiableItem, 0)
- cfg := s.s.Config()
- pk := s.s.PublicKey()
+ cfg := s.cfg
+ pk := s.pk
// Put configured repos first
for _, r := range cfg.Repos {
if r.Private && cfg.AuthRepo(r.Repo, pk) < wgit.AdminAccess {
@@ -1,20 +0,0 @@
-package session
-
-import (
- tea "github.com/charmbracelet/bubbletea"
- appCfg "github.com/charmbracelet/soft-serve/config"
- "github.com/charmbracelet/soft-serve/ui/git"
- "github.com/gliderlabs/ssh"
-)
-
-// Session is a interface representing a UI session.
-type Session interface {
- // Send sends a message to the parent Bubble Tea program.
- Send(tea.Msg)
- // Config returns the app configuration.
- Config() *appCfg.Config
- // PublicKey returns the public key of the user.
- PublicKey() ssh.PublicKey
- Session() ssh.Session
- Source() git.GitRepoSource
-}
@@ -7,6 +7,7 @@ import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/charmbracelet/soft-serve/config"
"github.com/charmbracelet/soft-serve/ui/common"
"github.com/charmbracelet/soft-serve/ui/components/footer"
"github.com/charmbracelet/soft-serve/ui/components/header"
@@ -14,7 +15,7 @@ import (
"github.com/charmbracelet/soft-serve/ui/git"
"github.com/charmbracelet/soft-serve/ui/pages/repo"
"github.com/charmbracelet/soft-serve/ui/pages/selection"
- "github.com/charmbracelet/soft-serve/ui/session"
+ "github.com/gliderlabs/ssh"
)
type page int
@@ -34,7 +35,9 @@ const (
// UI is the main UI model.
type UI struct {
- s session.Session
+ cfg *config.Config
+ session ssh.Session
+ rs git.GitRepoSource
initialRepo string
common common.Common
pages []common.Page
@@ -46,10 +49,13 @@ type UI struct {
}
// New returns a new UI model.
-func New(s session.Session, c common.Common, initialRepo string) *UI {
- h := header.New(c, s.Config().Name)
+func New(cfg *config.Config, s ssh.Session, c common.Common, initialRepo string) *UI {
+ src := &source{cfg.Source}
+ h := header.New(c, cfg.Name)
ui := &UI{
- s: s,
+ cfg: cfg,
+ session: s,
+ rs: src,
common: c,
pages: make([]common.Page, 2), // selection & repo
activePage: selectionPage,
@@ -122,8 +128,16 @@ func (ui *UI) SetSize(width, height int) {
// Init implements tea.Model.
func (ui *UI) Init() tea.Cmd {
- ui.pages[selectionPage] = selection.New(ui.s, ui.common)
- ui.pages[repoPage] = repo.New(ui.s, ui.common)
+ ui.pages[selectionPage] = selection.New(
+ ui.cfg,
+ ui.session.PublicKey(),
+ ui.common,
+ )
+ ui.pages[repoPage] = repo.New(
+ ui.cfg,
+ ui.rs,
+ ui.common,
+ )
ui.SetSize(ui.common.Width, ui.common.Height)
cmds := make([]tea.Cmd, 0)
cmds = append(cmds,
@@ -245,9 +259,8 @@ func (ui *UI) View() string {
}
func (ui *UI) setRepoCmd(rn string) tea.Cmd {
- rs := ui.s.Source()
return func() tea.Msg {
- for _, r := range rs.AllRepos() {
+ for _, r := range ui.rs.AllRepos() {
if r.Repo() == rn {
ui.activePage = repoPage
return repo.RepoMsg(r)
@@ -258,9 +271,8 @@ func (ui *UI) setRepoCmd(rn string) tea.Cmd {
}
func (ui *UI) initialRepoCmd(rn string) tea.Cmd {
- rs := ui.s.Source()
return func() tea.Msg {
- for _, r := range rs.AllRepos() {
+ for _, r := range ui.rs.AllRepos() {
if r.Repo() == rn {
ui.activePage = repoPage
return repo.RepoMsg(r)