You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lntop/ui/ui.go

52 lines
849 B
Go

5 years ago
package ui
import (
"fmt"
"github.com/jroimartin/gocui"
5 years ago
"github.com/edouardparis/lntop/app"
5 years ago
)
type Ui struct {
5 years ago
app *app.App
5 years ago
}
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
}
5 years ago
func New(app *app.App) *Ui {
return &Ui{app: app}
5 years ago
}