Fix help bar readability in terminal with bright background

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.
This commit is contained in:
Zdenek Crha 2020-09-21 12:11:39 +02:00
parent c0f6e6af7f
commit 6bf64841d3

View File

@ -17,13 +17,13 @@ type helpBar []struct {
func (hb helpBar) Render(maxX int) string { func (hb helpBar) Render(maxX int) string {
var builder strings.Builder var builder strings.Builder
for _, entry := range hb { for _, entry := range hb {
builder.WriteString(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))) builder.WriteString(colors.White(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))))
builder.WriteByte(' ') builder.WriteByte(' ')
} }
l := text.Len(builder.String()) l := text.Len(builder.String())
if l < maxX { if l < maxX {
builder.WriteString(colors.BlueBg(strings.Repeat(" ", maxX-l))) builder.WriteString(colors.White(colors.BlueBg(strings.Repeat(" ", maxX-l))))
} }
return builder.String() return builder.String()