mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
6bf64841d3
Set both background and foreground color when displaying help bar to avoid sitation where default foreground color used by terminal is hard to read on blue background (like cyan on blue or black on blue). Apply colors to whole generated help bar to avoid 'stripes' of different background color where whitespace is used between help items.
31 lines
579 B
Go
31 lines
579 B
Go
package termui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
text "github.com/MichaelMure/go-term-text"
|
|
|
|
"github.com/MichaelMure/git-bug/util/colors"
|
|
)
|
|
|
|
type helpBar []struct {
|
|
keys string
|
|
text string
|
|
}
|
|
|
|
func (hb helpBar) Render(maxX int) string {
|
|
var builder strings.Builder
|
|
for _, entry := range hb {
|
|
builder.WriteString(colors.White(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))))
|
|
builder.WriteByte(' ')
|
|
}
|
|
|
|
l := text.Len(builder.String())
|
|
if l < maxX {
|
|
builder.WriteString(colors.White(colors.BlueBg(strings.Repeat(" ", maxX-l))))
|
|
}
|
|
|
|
return builder.String()
|
|
}
|