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 Apr 29, 2024
1 parent f922e26 commit 56f284a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,26 @@ 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')
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(g.theme.Focused.ErrorMessage.Render(err.Error()))
foot.WriteString(g.theme.Focused.ErrorMessage.Render(err.Error()))
}
}
if foot.Len() > 0 && hasNonSpace(foot.String()) {
view.Grow(foot.Len() + 1) // +1 for newline/gap
view.WriteRune('\n')
view.WriteString(foot.String())
}
return view.String()
}

func isNonSpace(r rune) bool { return !unicode.IsSpace(r) }

Check failure on line 327 in group.go

View workflow job for this annotation

GitHub Actions / lint

undefined: unicode (typecheck)

Check failure on line 327 in group.go

View workflow job for this annotation

GitHub Actions / lint-soft

undefined: unicode (typecheck)

Check failure on line 327 in group.go

View workflow job for this annotation

GitHub Actions / test (1.19, ubuntu-latest)

undefined: unicode

Check failure on line 327 in group.go

View workflow job for this annotation

GitHub Actions / test (stable, ubuntu-latest)

undefined: unicode
func hasNonSpace(s string) bool { return strings.IndexFunc(s, isNonSpace) != -1 }

0 comments on commit 56f284a

Please sign in to comment.