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/views/channels.go

79 lines
1.3 KiB
Go

5 years ago
package views
import (
"context"
"fmt"
"github.com/jroimartin/gocui"
"github.com/edouardparis/lntop/network"
"github.com/edouardparis/lntop/network/models"
)
const CHANNELS = "channels"
5 years ago
type Channels struct {
*gocui.View
items []*models.Channel
network *network.Network
}
func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
var err error
c.View, err = g.SetView(CHANNELS, x0, y0, x1, y1)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
c.View.Frame = false
5 years ago
err = c.Refresh(g)
if err != nil {
return err
}
return nil
}
5 years ago
func (c *Channels) Refresh(g *gocui.Gui) error {
var err error
c.View, err = g.View(CHANNELS)
if err != nil {
return err
}
err = c.update(context.Background())
if err != nil {
return err
}
c.display()
return nil
}
func (c *Channels) update(ctx context.Context) error {
channels, err := c.network.ListChannels(ctx)
if err != nil {
return err
}
c.items = channels
return nil
}
5 years ago
func (c *Channels) display() {
for _, item := range c.items {
line := fmt.Sprintf("%d %9d %9d %s",
item.ID,
item.LocalBalance,
item.Capacity,
item.RemotePubKey,
)
fmt.Fprintln(c.View, line)
}
}
5 years ago
func NewChannels(network *network.Network) *Channels {
return &Channels{network: network}
5 years ago
}