mirror of
https://github.com/edouardparis/lntop
synced 2024-11-16 00:12:44 +00:00
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package views
|
|
|
|
import (
|
|
"github.com/edouardparis/lntop/ui/models"
|
|
"github.com/jroimartin/gocui"
|
|
)
|
|
|
|
type view interface {
|
|
Set(*gocui.Gui, int, int, int, int) error
|
|
Name() string
|
|
}
|
|
|
|
type Views struct {
|
|
Previous view
|
|
Help *Help
|
|
Header *Header
|
|
Summary *Summary
|
|
Channels *Channels
|
|
Channel *Channel
|
|
}
|
|
|
|
func (v Views) Get(name string) view {
|
|
switch name {
|
|
case CHANNELS:
|
|
return v.Channels
|
|
case HELP:
|
|
return v.Help
|
|
case CHANNEL:
|
|
return v.Channel
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (v *Views) SetPrevious(p view) {
|
|
v.Previous = p
|
|
}
|
|
|
|
func (v *Views) Layout(g *gocui.Gui, maxX, maxY int) error {
|
|
err := v.Header.Set(g, 0, -1, maxX, 1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = v.Summary.Set(g, 0, 1, maxX, 6)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return v.Channels.Set(g, 0, 6, maxX-1, maxY)
|
|
}
|
|
|
|
func New(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),
|
|
Channel: NewChannel(m.CurrentChannel),
|
|
}
|
|
}
|