summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2019-07-15 16:06:37 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2019-07-15 16:06:37 -0700
commit2cd92e147e6b7f60d76693f93f3a52e66a2fa9d1 (patch)
treee35a901a88fe58532d0526ceb97aad05406900e7
parente1f3488c4cb3a15dc95d5d2c32b8727fea9ddff2 (diff)
Refactor help menu
-rw-r--r--src/widgets/help.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/widgets/help.go b/src/widgets/help.go
index eaa6f59..54ddfbc 100644
--- a/src/widgets/help.go
+++ b/src/widgets/help.go
@@ -45,7 +45,11 @@ func NewHelpMenu() *HelpMenu {
}
func (self *HelpMenu) Resize(termWidth, termHeight int) {
- textWidth := 53
+ var textWidth = 0
+ for _, line := range strings.Split(KEYBINDS, "\n") {
+ textWidth = maxInt(len(line), textWidth)
+ }
+ textWidth += 2
textHeight := 22
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
@@ -65,3 +69,10 @@ func (self *HelpMenu) Draw(buf *ui.Buffer) {
}
}
}
+
+func maxInt(a int, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}