summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2021-02-16 16:24:34 -0600
committerSean E. Russell <ser@ser1.net>2021-02-16 16:24:34 -0600
commit5e0f04882612dd28756449f5100068b1a6975d5d (patch)
treea46bcea7fb550485dec89cf582e4622519c0ffd8
parenta59ad35ed53b6b32beca0dcbccaae67fc19bcf9c (diff)
Fix candidate for #167
-rw-r--r--widgets/help.go42
1 files changed, 12 insertions, 30 deletions
diff --git a/widgets/help.go b/widgets/help.go
index 73f67a0..1facf31 100644
--- a/widgets/help.go
+++ b/widgets/help.go
@@ -1,58 +1,40 @@
package widgets
import (
- "image"
"strings"
- ui "github.com/gizak/termui/v3"
+ "github.com/gizak/termui/v3/widgets"
lingo "github.com/xxxserxxx/lingo"
)
+// Used by all widgets
var tr lingo.Translations
-var keyBinds string
type HelpMenu struct {
- ui.Block
+ widgets.Paragraph
}
func NewHelpMenu(tra lingo.Translations) *HelpMenu {
tr = tra
- keyBinds = tr.Value("help.help")
- return &HelpMenu{
- Block: *ui.NewBlock(),
+ help := &HelpMenu{
+ Paragraph: *widgets.NewParagraph(),
}
+ help.Paragraph.Text = tra.Value("help.help")
+ return help
}
func (help *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
- for _, line := range strings.Split(keyBinds, "\n") {
+ var nlines int
+ var line string
+ for nlines, line = range strings.Split(help.Text, "\n") {
if textWidth < len(line) {
textWidth = len(line) + 2
}
}
- textHeight := strings.Count(keyBinds, "\n") + 1
+ textHeight := nlines + 2
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
- help.Block.SetRect(x, y, textWidth+x, textHeight+y)
-}
-
-func (help *HelpMenu) Draw(buf *ui.Buffer) {
- help.Block.Draw(buf)
-
- for y, line := range strings.Split(keyBinds, "\n") {
- for x, rune := range line {
- buf.SetCell(
- ui.NewCell(rune, ui.Theme.Default),
- image.Pt(help.Inner.Min.X+x, help.Inner.Min.Y+y-1),
- )
- }
- }
-}
-
-func maxInt(a int, b int) int {
- if a > b {
- return a
- }
- return b
+ help.Paragraph.SetRect(x, y, textWidth+x, textHeight+y)
}