From 7c23d176869d1940530ab5e6d63cfcf4a5019a6e Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 18 Aug 2021 17:12:17 -0400 Subject: [PATCH] Style footer/help --- tui/bubble.go | 38 ++++++++++++++++++++++++-------------- tui/help.go | 12 ++++++++++++ tui/style.go | 16 ++++++++++------ 3 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 tui/help.go diff --git a/tui/bubble.go b/tui/bubble.go index 87df275f3cf175f71a0436d49b84964a01f8b5cf..375828f37da0a12b3c46432e404d024bf51c9657 100644 --- a/tui/bubble.go +++ b/tui/bubble.go @@ -2,10 +2,12 @@ package tui import ( "fmt" + "io" "smoothie/git" "smoothie/tui/bubbles/commits" "smoothie/tui/bubbles/repo" "smoothie/tui/bubbles/selection" + "strings" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -142,26 +144,34 @@ func (b *Bubble) viewForBox(i int, width int, height int) string { return ls.Render(b.boxes[i].View()) } +func (b Bubble) footerView(w io.Writer) { + h := []helpEntry{ + {"tab", "section"}, + {"↑/↓", "navigate"}, + {"q", "quit"}, + } + for i, v := range h { + fmt.Fprint(w, v) + if i != len(h)-1 { + fmt.Fprint(w, helpDivider) + } + } +} + func (b *Bubble) View() string { + s := strings.Builder{} w := b.width - 3 - f := "" - s := "" - content := "" - h := headerStyle.Width(w - 2).Render(b.config.Name) - f += footerHighlightStyle.Bold(true).Render("tab ") - f += footerStyle.Render("section • ") - f += footerHighlightStyle.Bold(true).Render("j/k ") - f += footerStyle.Render("down/up • ") - f += footerHighlightStyle.Bold(true).Render("q ") - f += footerStyle.Render("quit") + s.WriteString(headerStyle.Width(w - 2).Render(b.config.Name)) + s.WriteRune('\n') switch b.state { case loadedState: lb := b.viewForBox(0, boxLeftWidth, 0) rb := b.viewForBox(1, b.width-boxLeftWidth-10, b.height-8) - s += lipgloss.JoinHorizontal(lipgloss.Top, lb, rb) + s.WriteString(lipgloss.JoinHorizontal(lipgloss.Top, lb, rb)) case errorState: - s += errorStyle.Render(fmt.Sprintf("Bummer: %s", b.error)) + s.WriteString(errorStyle.Render(fmt.Sprintf("Bummer: %s", b.error))) } - content = h + "\n" + s + "\n" + f - return appBoxStyle.Width(w).Height(b.height).Render(content) + s.WriteRune('\n') + b.footerView(&s) + return appBoxStyle.Width(w).Height(b.height).Render(s.String()) } diff --git a/tui/help.go b/tui/help.go new file mode 100644 index 0000000000000000000000000000000000000000..19b290aff51536cefc194b6eac3ef9b525824121 --- /dev/null +++ b/tui/help.go @@ -0,0 +1,12 @@ +package tui + +import "fmt" + +type helpEntry struct { + key string + val string +} + +func (h helpEntry) String() string { + return fmt.Sprintf("%s %s", helpKeyStyle.Render(h.key), helpValueStyle.Render(h.val)) +} diff --git a/tui/style.go b/tui/style.go index 1a45f6c4c55cd84194312ac59f50c164ca00cb41..d4ff52ae7cf06964c9dac96991f87fad27f4968f 100644 --- a/tui/style.go +++ b/tui/style.go @@ -38,11 +38,15 @@ var headerStyle = lipgloss.NewStyle(). var normalStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FFFFFF")) -var footerStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#373737")) - -var footerHighlightStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#DCDCDC")) - var errorStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FF00000")) + +var helpKeyStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("241")) + +var helpValueStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("239")) + +var helpDivider = lipgloss.NewStyle(). + Foreground(lipgloss.Color("237")). + SetString(" • ")