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/summary.go

78 lines
2.0 KiB
Go

5 years ago
package views
import (
"fmt"
"github.com/edouardparis/lntop/ui/color"
5 years ago
"github.com/edouardparis/lntop/ui/models"
5 years ago
"github.com/jroimartin/gocui"
)
const (
SUMMARY_LEFT = "summary_left"
SUMMARY_RIGHT = "summary_right"
)
type Summary struct {
5 years ago
left *gocui.View
right *gocui.View
info *models.Info
channelsBalance *models.ChannelsBalance
walletBalance *models.WalletBalance
5 years ago
}
func (s *Summary) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
var err error
5 years ago
s.left, err = g.SetView(SUMMARY_LEFT, x0, y0, x1/2, y1)
5 years ago
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
s.left.Frame = false
5 years ago
s.right, err = g.SetView(SUMMARY_RIGHT, x1/2, y0, x1, y1)
5 years ago
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
s.right.Frame = false
s.display()
return nil
}
func (s *Summary) display() {
s.left.Clear()
fmt.Fprintln(s.left, color.Green("[ Channels ]"))
5 years ago
fmt.Fprintln(s.left, fmt.Sprintf("%s %d (%s|%s)",
color.Cyan("balance:"),
s.channelsBalance.Balance+s.channelsBalance.PendingOpenBalance,
color.Green(fmt.Sprintf("%d", s.channelsBalance.Balance)),
color.Yellow(fmt.Sprintf("%d", s.channelsBalance.PendingOpenBalance)),
))
fmt.Fprintln(s.left, fmt.Sprintf("%s %d %s %d %s %d %s",
color.Cyan("state :"),
5 years ago
s.info.NumActiveChannels, color.Green("active"),
5 years ago
s.info.NumPendingChannels, color.Yellow("pending"),
5 years ago
s.info.NumInactiveChannels, color.Red("inactive"),
))
5 years ago
s.right.Clear()
5 years ago
fmt.Fprintln(s.right, color.Green("[ Wallet ]"))
fmt.Fprintln(s.right, fmt.Sprintf("%s %d (%s|%s)",
color.Cyan("balance:"),
s.walletBalance.TotalBalance,
color.Green(fmt.Sprintf("%d", s.walletBalance.ConfirmedBalance)),
color.Yellow(fmt.Sprintf("%d", s.walletBalance.UnconfirmedBalance)),
))
5 years ago
}
5 years ago
func NewSummary(info *models.Info, channelsBalance *models.ChannelsBalance, walletBalance *models.WalletBalance) *Summary {
return &Summary{
info: info,
channelsBalance: channelsBalance,
walletBalance: walletBalance,
}
5 years ago
}