3f8c9838db5549113bad03cd203c8465929b7e76

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

Message

Wrap long clone commands

Diff

  1diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go
  2index 84a77caa10e79b257bd98a6d13cd98608ae8a7d1..b2562fe57a4593e9edf3bbda0d8a83d2bf3df738 100644
  3--- a/tui/bubbles/repo/bubble.go
  4+++ b/tui/bubbles/repo/bubble.go
  5@@ -100,21 +100,39 @@ func (b *Bubble) GotoTop() {
  6 }
  7 
  8 func (b Bubble) headerView() string {
  9-	ts := b.styles.RepoTitle
 10-	ns := b.styles.RepoNote
 11-	if b.Active {
 12-		ts = ts.Copy().BorderForeground(b.styles.ActiveBorderColor)
 13-		ns = ns.Copy().BorderForeground(b.styles.ActiveBorderColor)
 14+	// Render repo title
 15+	title := b.name
 16+	if title == "config" {
 17+		title = "Home"
 18 	}
 19-	var gc string
 20-	n := truncate.StringWithTail(b.name, repoNameMaxWidth, "…")
 21-	if n == "config" {
 22-		n = "Home"
 23+	title = truncate.StringWithTail(title, repoNameMaxWidth, "…")
 24+	title = b.styles.RepoTitle.Render(title)
 25+
 26+	// Render clone command
 27+	var note string
 28+	if b.name == "config" {
 29+		note = ""
 30 	} else {
 31-		gc = fmt.Sprintf("git clone %s", b.sshAddress())
 32+		note = fmt.Sprintf("git clone %s", b.sshAddress())
 33+	}
 34+	noteStyle := b.styles.RepoNote.Copy().Width(
 35+		b.width - b.widthMargin - lipgloss.Width(title) -
 36+			b.styles.RepoTitleBox.GetHorizontalFrameSize(),
 37+	)
 38+	note = noteStyle.Render(note)
 39+
 40+	// Render borders on name and command
 41+	height := max(lipgloss.Height(title), lipgloss.Height(note))
 42+	titleBoxStyle := b.styles.RepoTitleBox.Copy().Height(height)
 43+	noteBoxStyle := b.styles.RepoNoteBox.Copy().Height(height)
 44+	if b.Active {
 45+		titleBoxStyle = titleBoxStyle.BorderForeground(b.styles.ActiveBorderColor)
 46+		noteBoxStyle = noteBoxStyle.BorderForeground(b.styles.ActiveBorderColor)
 47 	}
 48-	title := ts.Render(n)
 49-	note := ns.Width(b.width - b.widthMargin - lipgloss.Width(title)).Render(gc)
 50+	title = titleBoxStyle.Render(title)
 51+	note = noteBoxStyle.Render(note)
 52+
 53+	// Render
 54 	return lipgloss.JoinHorizontal(lipgloss.Top, title, note)
 55 }
 56 
 57@@ -201,3 +219,10 @@ func (b *Bubble) glamourize(md string) (string, error) {
 58 	mdt = wrap.String(wordwrap.String((mdt), w), w)
 59 	return mdt, nil
 60 }
 61+
 62+func max(a, b int) int {
 63+	if a > b {
 64+		return a
 65+	}
 66+	return b
 67+}
 68diff --git a/tui/style/style.go b/tui/style/style.go
 69index 5043a98a2ab67b581d3a69b5c71ace592efc6abc..b35a62efc36307619527f2b0769ced58d0574ea3 100644
 70--- a/tui/style/style.go
 71+++ b/tui/style/style.go
 72@@ -23,9 +23,11 @@ type Styles struct {
 73 	RepoNoteBorder  lipgloss.Border
 74 	RepoBodyBorder  lipgloss.Border
 75 
 76-	RepoTitle lipgloss.Style
 77-	RepoNote  lipgloss.Style
 78-	RepoBody  lipgloss.Style
 79+	RepoTitle    lipgloss.Style
 80+	RepoTitleBox lipgloss.Style
 81+	RepoNote     lipgloss.Style
 82+	RepoNoteBox  lipgloss.Style
 83+	RepoBody     lipgloss.Style
 84 
 85 	Footer      lipgloss.Style
 86 	HelpKey     lipgloss.Style
 87@@ -84,11 +86,11 @@ func DefaultStyles() *Styles {
 88 	s.RepoNoteBorder = lipgloss.Border{
 89 		Top:         "─",
 90 		Bottom:      "─",
 91-		Left:        "",
 92+		Left:        "│",
 93 		Right:       "│",
 94-		TopLeft:     "",
 95+		TopLeft:     "┬",
 96 		TopRight:    "╮",
 97-		BottomLeft:  "",
 98+		BottomLeft:  "┴",
 99 		BottomRight: "┤",
100 	}
101 
102@@ -104,16 +106,24 @@ func DefaultStyles() *Styles {
103 	}
104 
105 	s.RepoTitle = lipgloss.NewStyle().
106-		Border(s.RepoTitleBorder).
107-		BorderForeground(s.InactiveBorderColor).
108 		Padding(0, 2).
109 		Foreground(lipgloss.Color("252"))
110 
111+	s.RepoTitleBox = lipgloss.NewStyle().
112+		BorderStyle(s.RepoTitleBorder).
113+		BorderForeground(s.InactiveBorderColor)
114+
115 	s.RepoNote = lipgloss.NewStyle().
116-		Border(s.RepoNoteBorder, true, true, true, false).
117+		Padding(0, 2).
118+		Foreground(lipgloss.Color("168"))
119+
120+	s.RepoNoteBox = lipgloss.NewStyle().
121+		BorderStyle(s.RepoNoteBorder).
122 		BorderForeground(s.InactiveBorderColor).
123-		Foreground(lipgloss.Color("168")).
124-		Padding(0, 2)
125+		BorderTop(true).
126+		BorderRight(true).
127+		BorderBottom(true).
128+		BorderLeft(false)
129 
130 	s.RepoBody = lipgloss.NewStyle().
131 		BorderStyle(s.RepoBodyBorder).