Skip to content

Commit

Permalink
fix(group): do not render newline before empty help
Browse files Browse the repository at this point in the history
  • Loading branch information
ardnew committed May 7, 2024
1 parent 0a35040 commit dc7912f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,23 @@ func (g *Group) buildView() {

// View renders the group.
func (g *Group) View() string {
var view strings.Builder
// Write the footer view containing errors/keybindings to an alternate
// buffer to ensure it is non-empty before appending a line separator.
var view, foot strings.Builder
view.WriteString(g.viewport.View())
view.WriteRune('\n')
foot.WriteRune('\n')
errors := g.Errors()
if g.showHelp && len(errors) <= 0 {
view.WriteString(g.help.ShortHelpView(g.fields[g.paginator.Page].KeyBinds()))
foot.WriteString(g.help.ShortHelpView(g.fields[g.paginator.Page].KeyBinds()))
}
if g.showErrors {
for _, err := range errors {
view.WriteString(ThemeCharm().Focused.ErrorMessage.Render(err.Error()))
foot.WriteString(ThemeCharm().Focused.ErrorMessage.Render(err.Error()))
}
}
if strings.TrimSpace(foot.String()) != "" {
view.Grow(foot.Len())
view.WriteString(foot.String())
}
return view.String()
}

0 comments on commit dc7912f

Please sign in to comment.