From 144efbb344e6d0ac5903685dd8452f00a85f7e49 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 19 Aug 2021 20:39:22 -0400 Subject: [PATCH] Populate git clone command above READMEs --- tui/bubbles/repo/bubble.go | 28 ++++++++++++++++++++++++---- tui/commands.go | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go index ea518adaa0942eb088399eb74504a242527c122b..e4ea72c6800ebf199b21a956e1873f5c2f2fdb0f 100644 --- a/tui/bubbles/repo/bubble.go +++ b/tui/bubbles/repo/bubble.go @@ -2,7 +2,9 @@ package repo import ( "bytes" + "fmt" "smoothie/git" + "strconv" "text/template" "github.com/charmbracelet/bubbles/viewport" @@ -35,6 +37,13 @@ type Bubble struct { NoteStyle lipgloss.Style BodyStyle lipgloss.Style ActiveBorderColor lipgloss.Color + + // XXX: ideally, we get these from the parent as a pointer. Currently, we + // can't add a *tui.Config because it's an illegal import cycle. One + // solution would be to (rename and) move this Bubble into the parent + // package. + Host string + Port int64 } func NewBubble(rs *git.RepoSource, name string, width, wm, height, hm int, tmp interface{}) *Bubble { @@ -94,10 +103,13 @@ func (b Bubble) headerView() string { ts = ts.Copy().BorderForeground(b.ActiveBorderColor) ns = ns.Copy().BorderForeground(b.ActiveBorderColor) } - title := ts.Render(b.name) - note := ns. - Width(b.width - b.widthMargin - lipgloss.Width(title)). - Render("git clone ssh://...") + n := b.name + if n == "config" { + n = "Home" + } + title := ts.Render(n) + note := ns.Width(b.width - b.widthMargin - lipgloss.Width(title)). + Render(b.sshAddress()) return lipgloss.JoinHorizontal(lipgloss.Top, title, note) } @@ -114,6 +126,14 @@ func (b *Bubble) View() string { return header + body } +func (b Bubble) sshAddress() string { + p := ":" + strconv.Itoa(int(b.Port)) + if p == ":22" { + p = "" + } + return fmt.Sprintf("ssh://%s%s/%s", b.Host, p, b.name) +} + func (b *Bubble) setupCmd() tea.Msg { r, err := b.repoSource.GetRepo(b.name) if err == git.ErrMissingRepo { diff --git a/tui/commands.go b/tui/commands.go index 1c126872ca3cfa4867619d3d0060c29ad4fbd541..795e1eaec2c2c2aae4c90be900f5657861ca8b53 100644 --- a/tui/commands.go +++ b/tui/commands.go @@ -61,6 +61,8 @@ func (b *Bubble) setupCmd() tea.Msg { rb.NoteStyle = contentBoxNoteStyle rb.BodyStyle = contentBoxStyle rb.ActiveBorderColor = activeBorderColor + rb.Host = b.config.Host + rb.Port = b.config.Port initCmd := rb.Init() msg := initCmd() switch msg := msg.(type) {