mirror of
https://github.com/edouardparis/lntop
synced 2024-11-16 00:12:44 +00:00
40 lines
594 B
Go
40 lines
594 B
Go
package ui
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
"github.com/edouardparis/lntop/app"
|
|
"github.com/edouardparis/lntop/events"
|
|
)
|
|
|
|
func Run(ctx context.Context, app *app.App, sub chan *events.Event) error {
|
|
g, err := gocui.NewGui(gocui.OutputNormal)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer g.Close()
|
|
|
|
g.Cursor = true
|
|
ctrl := newController(app)
|
|
err = ctrl.SetModels(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
g.SetManagerFunc(ctrl.layout)
|
|
|
|
err = ctrl.setKeyBinding(g)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
go ctrl.Listen(ctx, g, sub)
|
|
|
|
err = g.MainLoop()
|
|
close(sub)
|
|
|
|
return err
|
|
}
|