summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-04-12 19:48:50 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-04-12 19:48:50 -0700
commit77c8a500fcbb53f83fc9aa1927922db578e3173a (patch)
treeecbb56e8b6496b8a13c08280f2e54350da765817
parent6b5db0cd092acf97e396f3d2484fd7f944fec92c (diff)
Init help widget before termui
-rw-r--r--main.go5
-rw-r--r--widgets/help.go9
2 files changed, 7 insertions, 7 deletions
diff --git a/main.go b/main.go
index 781cabf..3fb95c6 100644
--- a/main.go
+++ b/main.go
@@ -230,6 +230,8 @@ func main() {
widgetColors()
+ help = w.NewHelpMenu()
+
// inits termui
err := ui.Init()
if err != nil {
@@ -239,9 +241,6 @@ func main() {
setupGrid()
- // load help widget after init termui so that it has access to terminal size
- help = w.NewHelpMenu()
-
ui.On("<resize>", func(e ui.Event) {
ui.Body.Width, ui.Body.Height = e.Width, e.Height
ui.Body.Resize()
diff --git a/widgets/help.go b/widgets/help.go
index c86b02a..ed1bf77 100644
--- a/widgets/help.go
+++ b/widgets/help.go
@@ -32,16 +32,17 @@ type HelpMenu struct {
func NewHelpMenu() *HelpMenu {
block := ui.NewBlock()
- block.X = 48 // width - 1
- block.Y = 17 // height - 1
- block.XOffset = (ui.Body.Width - block.X) / 2 // X coordinate
- block.YOffset = (ui.Body.Height - block.Y) / 2 // Y coordinate
+ block.X = 48 // width - 1
+ block.Y = 17 // height - 1
return &HelpMenu{block}
}
func (self *HelpMenu) Buffer() *ui.Buffer {
buf := self.Block.Buffer()
+ self.Block.XOffset = (ui.Body.Width - self.Block.X) / 2 // X coordinate
+ self.Block.YOffset = (ui.Body.Height - self.Block.Y) / 2 // Y coordinate
+
for y, line := range strings.Split(KEYBINDS, "\n") {
for x, char := range line {
buf.SetCell(x+1, y, ui.NewCell(char, ui.Color(7), self.Bg))