2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-16 00:12:44 +00:00
lntop/ui/ui.go

40 lines
594 B
Go
Raw Normal View History

2019-03-18 12:38:14 +00:00
package ui
import (
2019-03-21 09:08:33 +00:00
"context"
2019-03-18 12:38:14 +00:00
"github.com/jroimartin/gocui"
2019-03-19 08:54:45 +00:00
"github.com/edouardparis/lntop/app"
2019-03-29 16:30:48 +00:00
"github.com/edouardparis/lntop/events"
2019-03-18 12:38:14 +00:00
)
2019-03-29 16:30:48 +00:00
func Run(ctx context.Context, app *app.App, sub chan *events.Event) error {
2019-03-18 12:38:14 +00:00
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
return err
}
defer g.Close()
2019-03-20 12:44:30 +00:00
g.Cursor = true
2019-03-22 08:36:13 +00:00
ctrl := newController(app)
2019-03-29 11:38:09 +00:00
err = ctrl.SetModels(ctx)
2019-03-19 13:19:49 +00:00
if err != nil {
2019-03-18 12:38:14 +00:00
return err
}
2019-03-29 11:38:09 +00:00
g.SetManagerFunc(ctrl.layout)
err = ctrl.setKeyBinding(g)
2019-03-22 17:14:43 +00:00
if err != nil {
return err
}
2019-04-01 11:24:49 +00:00
go ctrl.Listen(ctx, g, sub)
2019-03-29 16:30:48 +00:00
2019-03-19 13:19:49 +00:00
err = g.MainLoop()
2019-03-29 16:30:48 +00:00
close(sub)
2019-03-19 13:19:49 +00:00
2019-03-18 12:38:14 +00:00
return err
}