tson/gui/gui.go
2019-10-30 02:28:25 +09:00

39 lines
559 B
Go

package gui
import (
"log"
"github.com/rivo/tview"
)
type Gui struct {
Tree *Tree
App *tview.Application
Pages *tview.Pages
}
func New() *Gui {
g := &Gui{
Tree: NewTree(),
App: tview.NewApplication(),
Pages: tview.NewPages(),
}
return g
}
func (g *Gui) Run(i interface{}) error {
g.Tree.UpdateView(g, i)
grid := tview.NewGrid().
AddItem(g.Tree, 0, 0, 1, 1, 0, 0, true)
g.Pages.AddAndSwitchToPage("main", grid, true)
if err := g.App.SetRoot(g.Pages, true).Run(); err != nil {
log.Println(err)
return err
}
return nil
}