From 3f8c9838db5549113bad03cd203c8465929b7e76 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 13 Sep 2021 16:22:20 -0400 Subject: [PATCH] Wrap long clone commands --- tui/bubbles/repo/bubble.go | 49 ++++++++++++++++++++++++++++---------- tui/style/style.go | 32 ++++++++++++++++--------- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go index 84a77caa10e79b257bd98a6d13cd98608ae8a7d1..b2562fe57a4593e9edf3bbda0d8a83d2bf3df738 100644 --- a/tui/bubbles/repo/bubble.go +++ b/tui/bubbles/repo/bubble.go @@ -100,21 +100,39 @@ func (b *Bubble) GotoTop() { } func (b Bubble) headerView() string { - ts := b.styles.RepoTitle - ns := b.styles.RepoNote - if b.Active { - ts = ts.Copy().BorderForeground(b.styles.ActiveBorderColor) - ns = ns.Copy().BorderForeground(b.styles.ActiveBorderColor) + // Render repo title + title := b.name + if title == "config" { + title = "Home" } - var gc string - n := truncate.StringWithTail(b.name, repoNameMaxWidth, "…") - if n == "config" { - n = "Home" + title = truncate.StringWithTail(title, repoNameMaxWidth, "…") + title = b.styles.RepoTitle.Render(title) + + // Render clone command + var note string + if b.name == "config" { + note = "" } else { - gc = fmt.Sprintf("git clone %s", b.sshAddress()) + note = fmt.Sprintf("git clone %s", b.sshAddress()) + } + noteStyle := b.styles.RepoNote.Copy().Width( + b.width - b.widthMargin - lipgloss.Width(title) - + b.styles.RepoTitleBox.GetHorizontalFrameSize(), + ) + note = noteStyle.Render(note) + + // Render borders on name and command + height := max(lipgloss.Height(title), lipgloss.Height(note)) + titleBoxStyle := b.styles.RepoTitleBox.Copy().Height(height) + noteBoxStyle := b.styles.RepoNoteBox.Copy().Height(height) + if b.Active { + titleBoxStyle = titleBoxStyle.BorderForeground(b.styles.ActiveBorderColor) + noteBoxStyle = noteBoxStyle.BorderForeground(b.styles.ActiveBorderColor) } - title := ts.Render(n) - note := ns.Width(b.width - b.widthMargin - lipgloss.Width(title)).Render(gc) + title = titleBoxStyle.Render(title) + note = noteBoxStyle.Render(note) + + // Render return lipgloss.JoinHorizontal(lipgloss.Top, title, note) } @@ -201,3 +219,10 @@ func (b *Bubble) glamourize(md string) (string, error) { mdt = wrap.String(wordwrap.String((mdt), w), w) return mdt, nil } + +func max(a, b int) int { + if a > b { + return a + } + return b +} diff --git a/tui/style/style.go b/tui/style/style.go index 5043a98a2ab67b581d3a69b5c71ace592efc6abc..b35a62efc36307619527f2b0769ced58d0574ea3 100644 --- a/tui/style/style.go +++ b/tui/style/style.go @@ -23,9 +23,11 @@ type Styles struct { RepoNoteBorder lipgloss.Border RepoBodyBorder lipgloss.Border - RepoTitle lipgloss.Style - RepoNote lipgloss.Style - RepoBody lipgloss.Style + RepoTitle lipgloss.Style + RepoTitleBox lipgloss.Style + RepoNote lipgloss.Style + RepoNoteBox lipgloss.Style + RepoBody lipgloss.Style Footer lipgloss.Style HelpKey lipgloss.Style @@ -84,11 +86,11 @@ func DefaultStyles() *Styles { s.RepoNoteBorder = lipgloss.Border{ Top: "─", Bottom: "─", - Left: "", + Left: "│", Right: "│", - TopLeft: "", + TopLeft: "┬", TopRight: "╮", - BottomLeft: "", + BottomLeft: "┴", BottomRight: "┤", } @@ -104,16 +106,24 @@ func DefaultStyles() *Styles { } s.RepoTitle = lipgloss.NewStyle(). - Border(s.RepoTitleBorder). - BorderForeground(s.InactiveBorderColor). Padding(0, 2). Foreground(lipgloss.Color("252")) + s.RepoTitleBox = lipgloss.NewStyle(). + BorderStyle(s.RepoTitleBorder). + BorderForeground(s.InactiveBorderColor) + s.RepoNote = lipgloss.NewStyle(). - Border(s.RepoNoteBorder, true, true, true, false). + Padding(0, 2). + Foreground(lipgloss.Color("168")) + + s.RepoNoteBox = lipgloss.NewStyle(). + BorderStyle(s.RepoNoteBorder). BorderForeground(s.InactiveBorderColor). - Foreground(lipgloss.Color("168")). - Padding(0, 2) + BorderTop(true). + BorderRight(true). + BorderBottom(true). + BorderLeft(false) s.RepoBody = lipgloss.NewStyle(). BorderStyle(s.RepoBodyBorder).