From 8e362689e9c128c15aa181cd1107c003f537fa3c Mon Sep 17 00:00:00 2001 From: Edouard Paris Date: Thu, 28 Mar 2019 13:04:38 +0100 Subject: [PATCH] extract version number --- ui/controller.go | 17 ----------------- ui/ui.go | 2 -- ui/views/header.go | 13 ++++++++++++- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/ui/controller.go b/ui/controller.go index 5b9f88d..d21ff12 100644 --- a/ui/controller.go +++ b/ui/controller.go @@ -64,23 +64,6 @@ func (c *controller) Update(ctx context.Context) error { return nil } -func (c *controller) Refresh(ctx context.Context) func(*gocui.Gui) error { - return func(g *gocui.Gui) error { - info, err := c.app.Network.Info(ctx) - if err != nil { - return err - } - c.views.Header.Update(info.Alias, "lnd", info.Version) - - channels, err := c.app.Network.ListChannels(ctx) - if err != nil { - return err - } - c.views.Channels.Update(channels) - return nil - } -} - func quit(g *gocui.Gui, v *gocui.View) error { return gocui.ErrQuit } diff --git a/ui/ui.go b/ui/ui.go index 986691e..287a484 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -29,8 +29,6 @@ func Run(ctx context.Context, app *app.App) error { return err } - g.Update(ctrl.Refresh(ctx)) - err = g.MainLoop() if err != nil && err != gocui.ErrQuit { return err diff --git a/ui/views/header.go b/ui/views/header.go index de56aa3..7aee6d4 100644 --- a/ui/views/header.go +++ b/ui/views/header.go @@ -2,6 +2,7 @@ package views import ( "fmt" + "regexp" "github.com/edouardparis/lntop/ui/color" "github.com/jroimartin/gocui" @@ -11,6 +12,8 @@ const ( HEADER = "myheader" ) +var versionReg = regexp.MustCompile(`(\d+\.)?(\d+\.)?(\*|\d+)`) + type Header struct { alias string kind string @@ -25,7 +28,15 @@ func (h *Header) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { } } v.Frame = false - fmt.Fprintln(v, color.Cyan(fmt.Sprintf("[%s %s %s]", h.alias, h.kind, h.version))) + + version := h.version + matches := versionReg.FindStringSubmatch(h.version) + if len(matches) > 0 { + version = matches[0] + } + + fmt.Fprintln(v, fmt.Sprintf("%s %s %s", + color.CyanBg(h.alias), color.Cyan(h.kind), color.Cyan(version))) return nil }