mirror of
https://github.com/cjbassi/gotop.git
synced 2025-04-27 13:48:54 +08:00
Init help widget before termui
This commit is contained in:
parent
6b5db0cd09
commit
77c8a500fc
5
main.go
5
main.go
@ -230,6 +230,8 @@ func main() {
|
|||||||
|
|
||||||
widgetColors()
|
widgetColors()
|
||||||
|
|
||||||
|
help = w.NewHelpMenu()
|
||||||
|
|
||||||
// inits termui
|
// inits termui
|
||||||
err := ui.Init()
|
err := ui.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -239,9 +241,6 @@ func main() {
|
|||||||
|
|
||||||
setupGrid()
|
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.On("<resize>", func(e ui.Event) {
|
||||||
ui.Body.Width, ui.Body.Height = e.Width, e.Height
|
ui.Body.Width, ui.Body.Height = e.Width, e.Height
|
||||||
ui.Body.Resize()
|
ui.Body.Resize()
|
||||||
|
@ -34,14 +34,15 @@ func NewHelpMenu() *HelpMenu {
|
|||||||
block := ui.NewBlock()
|
block := ui.NewBlock()
|
||||||
block.X = 48 // width - 1
|
block.X = 48 // width - 1
|
||||||
block.Y = 17 // height - 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
|
|
||||||
return &HelpMenu{block}
|
return &HelpMenu{block}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HelpMenu) Buffer() *ui.Buffer {
|
func (self *HelpMenu) Buffer() *ui.Buffer {
|
||||||
buf := self.Block.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 y, line := range strings.Split(KEYBINDS, "\n") {
|
||||||
for x, char := range line {
|
for x, char := range line {
|
||||||
buf.SetCell(x+1, y, ui.NewCell(char, ui.Color(7), self.Bg))
|
buf.SetCell(x+1, y, ui.NewCell(char, ui.Color(7), self.Bg))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user