termui: help bar background goes all the width

This commit is contained in:
Michael Muré 2020-08-22 15:27:57 +02:00
parent 9ce84fc1a3
commit 8eb7faf67c
No known key found for this signature in database
GPG Key ID: A4457C029293126F
4 changed files with 14 additions and 8 deletions

View File

@ -128,7 +128,7 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Frame = false
v.FgColor = gocui.ColorWhite
_, _ = fmt.Fprint(v, bugTableHelp.Render())
_, _ = fmt.Fprint(v, bugTableHelp.Render(maxX))
}
_, err = g.SetCurrentView(bugTableView)

View File

@ -4,6 +4,8 @@ import (
"fmt"
"strings"
text "github.com/MichaelMure/go-term-text"
"github.com/MichaelMure/git-bug/util/colors"
)
@ -12,13 +14,17 @@ type helpBar []struct {
text string
}
func (hb helpBar) Render() string {
func (hb helpBar) Render(maxX int) string {
var builder strings.Builder
for i, entry := range hb {
if i != 0 {
builder.WriteByte(' ')
}
for _, entry := range hb {
builder.WriteString(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text)))
builder.WriteByte(' ')
}
l := text.Len(builder.String())
if l < maxX {
builder.WriteString(colors.BlueBg(strings.Repeat(" ", maxX-l)))
}
return builder.String()
}

View File

@ -153,7 +153,7 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
v.FgColor = gocui.ColorWhite
}
v.Clear()
_, _ = fmt.Fprint(v, labelSelectHelp.Render())
_, _ = fmt.Fprint(v, labelSelectHelp.Render(maxX))
if _, err = g.SetViewOnTop(labelSelectInstructionsView); err != nil {
return err
}

View File

@ -105,7 +105,7 @@ func (sb *showBug) layout(g *gocui.Gui) error {
}
v.Clear()
_, _ = fmt.Fprint(v, showBugHelp.Render())
_, _ = fmt.Fprint(v, showBugHelp.Render(maxX))
_, err = g.SetViewOnTop(showBugInstructionView)
if err != nil {