extract version number

pull/1/head
Edouard Paris 5 years ago
parent a76fcb2757
commit 8e362689e9

@ -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
}

@ -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

@ -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
}

Loading…
Cancel
Save