Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Init help widget before termui
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Apr 13, 2018
1 parent 6b5db0c commit 77c8a50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ func main() {

widgetColors()

help = w.NewHelpMenu()

// inits termui
err := ui.Init()
if err != nil {
Expand All @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions widgets/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 77c8a50

Please sign in to comment.