From e939038287b20163f364e78e9557d05fe976bbcf Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 19 Aug 2021 16:47:12 -0400 Subject: [PATCH] Add application-level margin --- tui/bubble.go | 28 ++++++++++++++-------------- tui/commands.go | 3 ++- tui/style.go | 4 +++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tui/bubble.go b/tui/bubble.go index 3cbd1cb3e..a699c8934 100644 --- a/tui/bubble.go +++ b/tui/bubble.go @@ -142,37 +142,36 @@ func (b *Bubble) viewForBox(i int) string { box := b.boxes[i] isActive := i == b.activeBox var s lipgloss.Style - var menuHeightFix int // TODO: figure out why we need this switch box.(type) { case *selection.Bubble: - menuHeightFix = 1 if isActive { s = menuActiveStyle - break + } else { + s = menuStyle } - s = menuStyle + h := b.height - + lipgloss.Height(b.headerView()) - + lipgloss.Height(b.footerView()) - + s.GetVerticalFrameSize() - + appBoxStyle.GetVerticalFrameSize() + + 1 // TODO: figure out why we need this + s = s.Copy().Height(h) case *repo.Bubble: if isActive { s = contentBoxActiveStyle } else { s = contentBoxStyle } - const repoWidthFix = 1 // TODO: figure out why we need this w := b.width - lipgloss.Width(b.viewForBox(0)) - appBoxStyle.GetHorizontalFrameSize() - - s.GetHorizontalFrameSize() + repoWidthFix + s.GetHorizontalFrameSize() + + 1 // TODO: figure out why we need this s = s.Copy().Width(w) default: panic(fmt.Sprintf("unknown box type %T", box)) } - h := b.height - - lipgloss.Height(b.headerView()) - - lipgloss.Height(b.footerView()) - - s.GetVerticalFrameSize() - - appBoxStyle.GetVerticalFrameSize() + - menuHeightFix - return s.Copy().Height(h).Render(box.View()) + return s.Render(box.View()) } func (b Bubble) headerView() string { @@ -202,7 +201,7 @@ func (b Bubble) footerView() string { fmt.Fprint(w, helpDivider) } } - return footerStyle.Render(w.String()) + return footerStyle.Copy().Width(b.width).Render(w.String()) } func (b Bubble) errorView() string { @@ -232,6 +231,7 @@ func (b Bubble) View() string { case errorState: s.WriteString(b.errorView()) } + s.WriteRune('\n') s.WriteString(b.footerView()) return appBoxStyle.Render(s.String()) } diff --git a/tui/commands.go b/tui/commands.go index 173e1d89d..b8db6e08c 100644 --- a/tui/commands.go +++ b/tui/commands.go @@ -53,7 +53,8 @@ func (b *Bubble) setupCmd() tea.Msg { // TODO: also send this along with a tea.WindowSizeMsg var heightMargin = lipgloss.Height(b.headerView()) + lipgloss.Height(b.footerView()) + - contentBoxStyle.GetVerticalFrameSize() + contentBoxStyle.GetVerticalFrameSize() + + appBoxStyle.GetVerticalMargins() rb := repo.NewBubble(b.repoSource, me.Repo, width, boxLeftWidth, b.height, heightMargin, tmplConfig) initCmd := rb.Init() msg := initCmd() diff --git a/tui/style.go b/tui/style.go index 8c419a7e4..cd0f807a3 100644 --- a/tui/style.go +++ b/tui/style.go @@ -7,11 +7,13 @@ import ( var activeBorderColor = lipgloss.Color("62") var inactiveBorderColor = lipgloss.Color("236") -var appBoxStyle = lipgloss.NewStyle() +var appBoxStyle = lipgloss.NewStyle(). + Margin(1, 2) var headerStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("62")). Align(lipgloss.Right). + PaddingRight(1). Bold(true) var menuStyle = lipgloss.NewStyle().