144efbb344e6d0ac5903685dd8452f00a85f7e49

Author
Christian Rocha <christian@rocha.is>
Committer
Christian Rocha <christian@rocha.is>
Date

Message

Populate git clone command above READMEs

Diff

 1diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go
 2index ea518adaa0942eb088399eb74504a242527c122b..e4ea72c6800ebf199b21a956e1873f5c2f2fdb0f 100644
 3--- a/tui/bubbles/repo/bubble.go
 4+++ b/tui/bubbles/repo/bubble.go
 5@@ -2,7 +2,9 @@ package repo
 6 
 7 import (
 8 	"bytes"
 9+	"fmt"
10 	"smoothie/git"
11+	"strconv"
12 	"text/template"
13 
14 	"github.com/charmbracelet/bubbles/viewport"
15@@ -35,6 +37,13 @@ type Bubble struct {
16 	NoteStyle         lipgloss.Style
17 	BodyStyle         lipgloss.Style
18 	ActiveBorderColor lipgloss.Color
19+
20+	// XXX: ideally, we get these from the parent as a pointer. Currently, we
21+	// can't add a *tui.Config because it's an illegal import cycle. One
22+	// solution would be to (rename and) move this Bubble into the parent
23+	// package.
24+	Host string
25+	Port int64
26 }
27 
28 func NewBubble(rs *git.RepoSource, name string, width, wm, height, hm int, tmp interface{}) *Bubble {
29@@ -94,10 +103,13 @@ func (b Bubble) headerView() string {
30 		ts = ts.Copy().BorderForeground(b.ActiveBorderColor)
31 		ns = ns.Copy().BorderForeground(b.ActiveBorderColor)
32 	}
33-	title := ts.Render(b.name)
34-	note := ns.
35-		Width(b.width - b.widthMargin - lipgloss.Width(title)).
36-		Render("git clone ssh://...")
37+	n := b.name
38+	if n == "config" {
39+		n = "Home"
40+	}
41+	title := ts.Render(n)
42+	note := ns.Width(b.width - b.widthMargin - lipgloss.Width(title)).
43+		Render(b.sshAddress())
44 	return lipgloss.JoinHorizontal(lipgloss.Top, title, note)
45 }
46 
47@@ -114,6 +126,14 @@ func (b *Bubble) View() string {
48 	return header + body
49 }
50 
51+func (b Bubble) sshAddress() string {
52+	p := ":" + strconv.Itoa(int(b.Port))
53+	if p == ":22" {
54+		p = ""
55+	}
56+	return fmt.Sprintf("ssh://%s%s/%s", b.Host, p, b.name)
57+}
58+
59 func (b *Bubble) setupCmd() tea.Msg {
60 	r, err := b.repoSource.GetRepo(b.name)
61 	if err == git.ErrMissingRepo {
62diff --git a/tui/commands.go b/tui/commands.go
63index 1c126872ca3cfa4867619d3d0060c29ad4fbd541..795e1eaec2c2c2aae4c90be900f5657861ca8b53 100644
64--- a/tui/commands.go
65+++ b/tui/commands.go
66@@ -61,6 +61,8 @@ func (b *Bubble) setupCmd() tea.Msg {
67 		rb.NoteStyle = contentBoxNoteStyle
68 		rb.BodyStyle = contentBoxStyle
69 		rb.ActiveBorderColor = activeBorderColor
70+		rb.Host = b.config.Host
71+		rb.Port = b.config.Port
72 		initCmd := rb.Init()
73 		msg := initCmd()
74 		switch msg := msg.(type) {