Skip to content

Commit

Permalink
refactor(gui): add a gui struct to handle all related to the gui
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Apr 28, 2021
1 parent c617dfe commit bcfdcda
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package gui

import "github.com/jroimartin/gocui"

// Gui wraps the gocui Gui object which handles rendering and events
type Gui struct {
g *gocui.Gui
}

// New builds a new gui handler
func New(g *gocui.Gui) *Gui {
return &Gui{
g: g,
}
}

// Run setup the gui with keybindings and start the mainloop
func (gui *Gui) Run() error {
defer gui.g.Close()

gui.g.SetManagerFunc(gui.layout)

if err := gui.g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, Quit); err != nil {
return err
}

if err := gui.g.MainLoop(); err != nil && err != gocui.ErrQuit {
return err
}

return nil
}

0 comments on commit bcfdcda

Please sign in to comment.