2020-04-12 12:11:01 +03:00
|
|
|
package termui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2020-08-22 16:27:57 +03:00
|
|
|
text "github.com/MichaelMure/go-term-text"
|
|
|
|
|
2020-04-12 12:11:01 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/colors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type helpBar []struct {
|
|
|
|
keys string
|
|
|
|
text string
|
|
|
|
}
|
|
|
|
|
2020-08-22 16:27:57 +03:00
|
|
|
func (hb helpBar) Render(maxX int) string {
|
2020-04-12 12:11:01 +03:00
|
|
|
var builder strings.Builder
|
2020-08-22 16:27:57 +03:00
|
|
|
for _, entry := range hb {
|
2020-09-21 13:11:39 +03:00
|
|
|
builder.WriteString(colors.White(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))))
|
2020-08-22 16:27:57 +03:00
|
|
|
builder.WriteByte(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
l := text.Len(builder.String())
|
|
|
|
if l < maxX {
|
2020-09-21 13:11:39 +03:00
|
|
|
builder.WriteString(colors.White(colors.BlueBg(strings.Repeat(" ", maxX-l))))
|
2020-04-12 12:11:01 +03:00
|
|
|
}
|
2020-08-22 16:27:57 +03:00
|
|
|
|
2020-04-12 12:11:01 +03:00
|
|
|
return builder.String()
|
|
|
|
}
|