2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-04 06:00:14 +00:00
lntop/ui/views/views.go

69 lines
1.2 KiB
Go
Raw Normal View History

2019-03-28 08:47:47 +00:00
package views
2019-03-28 13:07:46 +00:00
import (
"github.com/edouardparis/lntop/ui/models"
"github.com/jroimartin/gocui"
)
2019-03-28 08:47:47 +00:00
2019-04-02 08:14:39 +00:00
type view interface {
Set(*gocui.Gui, int, int, int, int) error
Name() string
}
2019-03-28 08:47:47 +00:00
type Views struct {
2019-04-02 08:14:39 +00:00
Previous view
Help *Help
2019-03-28 08:47:47 +00:00
Header *Header
Summary *Summary
Channels *Channels
2019-04-02 12:27:51 +00:00
Channel *Channel
2019-03-28 08:47:47 +00:00
Footer *Footer
}
2019-04-02 08:14:39 +00:00
func (v Views) Get(name string) view {
switch name {
case CHANNELS:
return v.Channels
case HELP:
return v.Help
2019-04-03 08:14:47 +00:00
case CHANNEL:
return v.Channel
2019-04-02 08:14:39 +00:00
default:
return nil
}
}
func (v *Views) SetPrevious(p view) {
v.Previous = p
}
2019-03-28 08:47:47 +00:00
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
}
err = v.Channels.Set(g, 0, 6, maxX-1, maxY-1)
if err != nil {
return err
}
return v.Footer.Set(g, 0, maxY-2, maxX, maxY)
}
2019-03-28 13:07:46 +00:00
func New(m *models.Models) *Views {
2019-03-28 08:47:47 +00:00
return &Views{
2019-03-28 13:07:46 +00:00
Header: NewHeader(m.Info),
2019-03-28 08:47:47 +00:00
Footer: NewFooter(),
2019-04-02 08:14:39 +00:00
Help: NewHelp(),
2019-03-29 11:52:49 +00:00
Summary: NewSummary(m.Info, m.ChannelsBalance, m.WalletBalance, m.Channels),
2019-03-29 08:30:05 +00:00
Channels: NewChannels(m.Channels),
2019-04-02 12:27:51 +00:00
Channel: NewChannel(m.CurrentChannel),
2019-03-28 08:47:47 +00:00
}
}