config: add Views

pull/10/head
Edouard Paris 5 years ago
parent d073bf206c
commit aa3f140ca5

@ -14,6 +14,7 @@ import (
type Config struct {
Logger Logger `toml:"logger"`
Network Network `toml:"network"`
Views Views `toml:"views"`
}
type Logger struct {
@ -34,6 +35,14 @@ type Network struct {
PoolCapacity int `toml:"pool_capacity"`
}
type Views struct {
Channels *View `toml:"channels"`
}
type View struct {
Columns []string `toml:"columns"`
}
func Load(path string) (*Config, error) {
c := &Config{}

@ -262,6 +262,6 @@ func newController(app *app.App) *controller {
return &controller{
logger: app.Logger.With(logging.String("logger", "controller")),
models: m,
views: views.New(m),
views: views.New(app.Config.Views, m),
}
}

@ -8,6 +8,7 @@ import (
"golang.org/x/text/language"
"golang.org/x/text/message"
"github.com/edouardparis/lntop/config"
netmodels "github.com/edouardparis/lntop/network/models"
"github.com/edouardparis/lntop/ui/color"
"github.com/edouardparis/lntop/ui/models"
@ -21,6 +22,7 @@ const (
type Channels struct {
index int
cfg *config.View
columns *gocui.View
view *gocui.View
channels *models.Channels
@ -160,6 +162,10 @@ func (c *Channels) display() {
}
}
func NewChannels(cfg *config.View, channels *models.Channels) *Channels {
return &Channels{cfg: cfg, channels: channels}
}
func channelPrivate(c *netmodels.Channel) string {
if c.Private {
return color.Red("private")
@ -226,7 +232,3 @@ func gauge(c *netmodels.Channel) string {
}
return fmt.Sprintf("[%s] %2d%%", buffer.String(), c.LocalBalance*100/c.Capacity)
}
func NewChannels(channels *models.Channels) *Channels {
return &Channels{channels: channels}
}

@ -1,6 +1,7 @@
package views
import (
"github.com/edouardparis/lntop/config"
"github.com/edouardparis/lntop/ui/models"
"github.com/jroimartin/gocui"
)
@ -58,12 +59,12 @@ func (v *Views) Layout(g *gocui.Gui, maxX, maxY int) error {
return v.Channels.Set(g, 0, 6, maxX-1, maxY)
}
func New(m *models.Models) *Views {
func New(cfg config.Views, m *models.Models) *Views {
return &Views{
Header: NewHeader(m.Info),
Help: NewHelp(),
Summary: NewSummary(m.Info, m.ChannelsBalance, m.WalletBalance, m.Channels),
Channels: NewChannels(m.Channels),
Channels: NewChannels(cfg.Channels, m.Channels),
Channel: NewChannel(m.CurrentChannel),
}
}

Loading…
Cancel
Save