2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-17 21:26:12 +00:00
lntop/ui/views/header.go

68 lines
1.3 KiB
Go
Raw Normal View History

2019-03-22 17:14:43 +00:00
package views
import (
"fmt"
2019-03-28 12:04:38 +00:00
"regexp"
2019-03-22 17:14:43 +00:00
2019-03-25 17:29:25 +00:00
"github.com/edouardparis/lntop/ui/color"
2019-03-28 13:07:46 +00:00
"github.com/edouardparis/lntop/ui/models"
2019-03-22 17:14:43 +00:00
"github.com/jroimartin/gocui"
)
const (
HEADER = "myheader"
)
2019-03-28 12:04:38 +00:00
var versionReg = regexp.MustCompile(`(\d+\.)?(\d+\.)?(\*|\d+)`)
2019-03-22 17:14:43 +00:00
type Header struct {
2019-03-28 13:07:46 +00:00
Info *models.Info
2019-03-22 17:14:43 +00:00
}
func (h *Header) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
v, err := g.SetView(HEADER, x0, y0, x1, y0+2)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
v.Frame = false
2019-03-28 12:04:38 +00:00
2019-03-28 13:07:46 +00:00
version := h.Info.Version
matches := versionReg.FindStringSubmatch(h.Info.Version)
2019-03-28 12:04:38 +00:00
if len(matches) > 0 {
version = matches[0]
}
2019-03-29 09:06:30 +00:00
chain := ""
if len(h.Info.Chains) > 0 {
chain = h.Info.Chains[0]
}
network := "testnet"
if !h.Info.Testnet {
network = "mainnet"
}
sync := color.Yellow()("[syncing]")
2019-03-29 09:06:30 +00:00
if h.Info.Synced {
sync = color.Green()("[synced]")
2019-03-29 09:06:30 +00:00
}
2019-04-01 16:36:12 +00:00
v.Clear()
cyan := color.Cyan()
2019-03-29 09:06:30 +00:00
fmt.Fprintln(v, fmt.Sprintf("%s %s %s %s %s %s",
color.Cyan(color.Background)(h.Info.Alias),
cyan(fmt.Sprintf("%s-v%s", "lnd", version)),
2019-03-29 09:06:30 +00:00
fmt.Sprintf("%s %s", chain, network),
sync,
fmt.Sprintf("%s %d", cyan("height:"), h.Info.BlockHeight),
fmt.Sprintf("%s %d", cyan("peers:"), h.Info.NumPeers),
2019-03-28 12:10:49 +00:00
))
2019-03-22 17:14:43 +00:00
return nil
}
2019-03-28 13:07:46 +00:00
func NewHeader(info *models.Info) *Header {
return &Header{Info: info}
2019-03-22 17:14:43 +00:00
}