refac view channel

pull/1/head
Edouard Paris 5 years ago
parent 78c41c0741
commit 3a5b65b8cc

@ -132,8 +132,33 @@ func (c *controller) OnEnter(g *gocui.Gui, v *gocui.View) error {
case views.CHANNELS:
c.views.SetPrevious(view)
_, cy := v.Cursor()
c.models.SetCurrentChannel(context.Background(), cy)
return c.views.Channel.Set(g, 0, 6, maxX-1, maxY-1)
err := c.models.SetCurrentChannel(context.Background(), cy)
if err != nil {
return err
}
err = c.views.Channel.Set(g, 0, 6, maxX-1, maxY-1)
if err != nil {
return err
}
_, err = g.SetCurrentView(c.views.Channel.Name())
return err
case views.CHANNEL:
err := g.DeleteView(view.Name())
if err != nil {
return err
}
if c.views.Previous != nil {
_, err := g.SetCurrentView(c.views.Previous.Name())
return err
}
err = c.views.Channels.Set(g, 0, 6, maxX-1, maxY-1)
if err != nil {
return err
}
}
return nil
}

@ -7,7 +7,7 @@ type Channels struct {
}
func (c *Channels) Get(index int) *models.Channel {
if index < 0 || index > len(c.Items) {
if index < 0 || index > len(c.Items)-1 {
return nil
}

@ -119,20 +119,45 @@ func (c Channel) Empty() bool {
}
func (c *Channel) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
v, err := g.SetView(CHANNEL, x0-1, y0, x1+2, y1)
header, err := g.SetView(CHANNELS_COLUMNS, x0-1, y0, x1+2, y0+2)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
header.Frame = false
header.BgColor = gocui.ColorGreen
header.FgColor = gocui.ColorBlack | gocui.AttrBold
header.Clear()
fmt.Fprintln(header, "Channel")
v, err := g.SetView(CHANNEL, x0-1, y0+1, x1+2, y1)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
v.Frame = false
c.display(v)
return nil
}
func (c *Channel) display(v *gocui.View) {
v.Clear()
channel := c.channel.Item
fmt.Fprintln(v, active(channel))
fmt.Fprintln(v, fmt.Sprintf("%s %d",
color.Cyan(" ID:"), channel.ID))
fmt.Fprintln(v, fmt.Sprintf("%s %d",
color.Cyan(" Capacity:"), channel.Capacity))
fmt.Fprintln(v, fmt.Sprintf("%s %d",
color.Cyan(" Local Balance:"), channel.LocalBalance))
fmt.Fprintln(v, fmt.Sprintf("%s %d",
color.Cyan("ID:"), c.channel.Item.ID))
color.Cyan(" Remote Balance:"), channel.RemoteBalance))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Remote PubKey:"), channel.RemotePubKey))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Channel Point:"), channel.ChannelPoint))
}
func NewChannel(channel *models.Channel) *Channel {

Loading…
Cancel
Save