mirror of
https://github.com/edouardparis/lntop
synced 2024-11-16 00:12:44 +00:00
52 lines
849 B
Go
52 lines
849 B
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
"github.com/edouardparis/lntop/app"
|
|
)
|
|
|
|
type Ui struct {
|
|
app *app.App
|
|
}
|
|
|
|
func (u *Ui) Run() error {
|
|
g, err := gocui.NewGui(gocui.OutputNormal)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer g.Close()
|
|
|
|
g.SetManagerFunc(layout)
|
|
|
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func layout(g *gocui.Gui) error {
|
|
maxX, maxY := g.Size()
|
|
if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
|
|
if err != gocui.ErrUnknownView {
|
|
return err
|
|
}
|
|
fmt.Fprintln(v, "Hello world!")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func quit(g *gocui.Gui, v *gocui.View) error {
|
|
return gocui.ErrQuit
|
|
}
|
|
|
|
func New(app *app.App) *Ui {
|
|
return &Ui{app: app}
|
|
}
|