b79f14ca37923f4c3f04f8dc211feafa3e9a6607

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

Message

Style and help for the error state

Diff

  1diff --git a/tui/bubble.go b/tui/bubble.go
  2index 8c937fa27a88d354a42bf101517b6ce8d9337522..3cbd1cb3e4e07b37cf0e3ad29ff4182a1e01d36f 100644
  3--- a/tui/bubble.go
  4+++ b/tui/bubble.go
  5@@ -182,13 +182,19 @@ func (b Bubble) headerView() string {
  6 
  7 func (b Bubble) footerView() string {
  8 	w := &strings.Builder{}
  9-	h := []helpEntry{
 10-		{"tab", "section"},
 11-		{"↑/↓", "navigate"},
 12-		{"q", "quit"},
 13-	}
 14-	if _, ok := b.boxes[b.activeBox].(*repo.Bubble); ok {
 15-		h = append(h[:2], helpEntry{"f/b", "pgup/pgdown"}, h[2])
 16+	var h []helpEntry
 17+	switch b.state {
 18+	case errorState:
 19+		h = []helpEntry{{"q", "quit"}}
 20+	default:
 21+		h = []helpEntry{
 22+			{"tab", "section"},
 23+			{"↑/↓", "navigate"},
 24+			{"q", "quit"},
 25+		}
 26+		if _, ok := b.boxes[b.activeBox].(*repo.Bubble); ok {
 27+			h = append(h[:2], helpEntry{"f/b", "pgup/pgdown"}, h[2])
 28+		}
 29 	}
 30 	for i, v := range h {
 31 		fmt.Fprint(w, v)
 32@@ -199,6 +205,21 @@ func (b Bubble) footerView() string {
 33 	return footerStyle.Render(w.String())
 34 }
 35 
 36+func (b Bubble) errorView() string {
 37+	s := lipgloss.JoinHorizontal(
 38+		lipgloss.Top,
 39+		errorHeaderStyle.Render("Bummer"),
 40+		errorBodyStyle.Render(b.error),
 41+	)
 42+	h := b.height -
 43+		appBoxStyle.GetVerticalFrameSize() -
 44+		lipgloss.Height(b.headerView()) -
 45+		lipgloss.Height(b.footerView()) -
 46+		contentBoxStyle.GetVerticalFrameSize() +
 47+		3 // TODO: figure out why we need this
 48+	return errorStyle.Copy().Height(h).Render(s)
 49+}
 50+
 51 func (b Bubble) View() string {
 52 	s := strings.Builder{}
 53 	s.WriteString(b.headerView())
 54@@ -209,7 +230,7 @@ func (b Bubble) View() string {
 55 		rb := b.viewForBox(1)
 56 		s.WriteString(lipgloss.JoinHorizontal(lipgloss.Top, lb, rb))
 57 	case errorState:
 58-		s.WriteString(errorStyle.Render(fmt.Sprintf("Bummer: %s", b.error)))
 59+		s.WriteString(b.errorView())
 60 	}
 61 	s.WriteString(b.footerView())
 62 	return appBoxStyle.Render(s.String())
 63diff --git a/tui/style.go b/tui/style.go
 64index 998de114e3e4ae269a8fa4d310161fd5e43d0e9e..1441c32f8d629bc3f5d15e66675e41c3addb452a 100644
 65--- a/tui/style.go
 66+++ b/tui/style.go
 67@@ -7,15 +7,6 @@ import (
 68 var activeBorderColor = lipgloss.Color("243")
 69 var inactiveBorderColor = lipgloss.Color("236")
 70 
 71-var hiddenBorder = lipgloss.Border{
 72-	TopLeft:     " ",
 73-	Top:         " ",
 74-	TopRight:    " ",
 75-	BottomLeft:  " ",
 76-	Bottom:      " ",
 77-	BottomRight: " ",
 78-}
 79-
 80 var appBoxStyle = lipgloss.NewStyle()
 81 
 82 var menuStyle = lipgloss.NewStyle().
 83@@ -66,7 +57,18 @@ var menuCursor = lipgloss.NewStyle().
 84 	SetString(">")
 85 
 86 var errorStyle = lipgloss.NewStyle().
 87-	Foreground(lipgloss.Color("#FF00000"))
 88+	Padding(1)
 89+
 90+var errorHeaderStyle = lipgloss.NewStyle().
 91+	Foreground(lipgloss.Color("230")).
 92+	Background(lipgloss.Color("204")).
 93+	Bold(true).
 94+	Padding(0, 1)
 95+
 96+var errorBodyStyle = lipgloss.NewStyle().
 97+	Foreground(lipgloss.Color("252")).
 98+	MarginLeft(2).
 99+	Width(52) // for now
100 
101 var helpDivider = lipgloss.NewStyle().
102 	Foreground(lipgloss.Color("237")).