Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(group): do not render newline before empty help #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading