Skip to content

Commit

Permalink
Merge pull request #15 from edouardparis/v0.0.2
Browse files Browse the repository at this point in the history
V0.0.2
  • Loading branch information
edouardparis authored Apr 29, 2019
2 parents cdcb1d0 + fd0fb6d commit d073bf2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/edouardparis/lntop/ui"
)

const version = "v0.0.1"
const version = "v0.0.2"

// New creates a new cli app.
func New() *cli.App {
Expand Down
14 changes: 12 additions & 2 deletions ui/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func (c *controller) OnEnter(g *gocui.Gui, v *gocui.View) error {
switch view.Name() {
case views.CHANNELS:
c.views.SetPrevious(view)
_, cy := v.Cursor()
err := c.models.SetCurrentChannel(context.Background(), cy)
index := c.views.Channels.Index()
err := c.models.SetCurrentChannel(context.Background(), index)
if err != nil {
return err
}
Expand Down Expand Up @@ -214,6 +214,11 @@ func (c *controller) setKeyBinding(g *gocui.Gui) error {
return err
}

err = g.SetKeybinding("", 'q', gocui.ModNone, quit)
if err != nil {
return err
}

err = g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, c.cursorUp)
if err != nil {
return err
Expand Down Expand Up @@ -244,6 +249,11 @@ func (c *controller) setKeyBinding(g *gocui.Gui) error {
return err
}

err = g.SetKeybinding("", 'h', gocui.ModNone, c.Help)
if err != nil {
return err
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions ui/models/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (c *Channels) List() []*models.Channel {
return c.list
}

func (c *Channels) Len() int {
return len(c.list)
}

func (c *Channels) Get(index int) *models.Channel {
if index < 0 || index > len(c.list)-1 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion ui/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *Models) RefreshChannels(ctx context.Context) error {
channels[i].Node, err = m.network.GetNode(ctx,
channels[i].RemotePubKey)
if err != nil {
m.logger.Error("refreshChannels: cannot find Node",
m.logger.Debug("refreshChannels: cannot find Node",
logging.String("pubkey", channels[i].RemotePubKey))
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/views/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *Channel) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
header.Clear()
fmt.Fprintln(header, "Channel")

v, err := g.SetView(CHANNEL, x0-1, y0+1, x1+2, y1-2)
v, err := g.SetView(CHANNEL, x0-1, y0+1, x1+2, y1-1)
if err != nil {
if err != gocui.ErrUnknownView {
return err
Expand Down
16 changes: 15 additions & 1 deletion ui/views/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ const (
)

type Channels struct {
index int
columns *gocui.View
view *gocui.View
channels *models.Channels
}

func (c Channels) Index() int {
return c.index
}

func (c Channels) Name() string {
return CHANNELS
}
Expand All @@ -35,10 +40,17 @@ func (c *Channels) Wrap(v *gocui.View) view {
}

func (c *Channels) CursorDown() error {
if c.channels.Len() <= c.index+1 {
return nil
}
c.index++
return cursorDown(c.view, 1)
}

func (c *Channels) CursorUp() error {
if c.index > 0 {
c.index--
}
return cursorUp(c.view, 1)
}

Expand Down Expand Up @@ -166,7 +178,9 @@ func channelID(c *netmodels.Channel) string {

func alias(c *netmodels.Channel) string {
if c.Node == nil || c.Node.Alias == "" {
return c.RemotePubKey[:19]
return c.RemotePubKey[:24]
} else if len(c.Node.Alias) > 25 {
return c.Node.Alias[:24]
}

return c.Node.Alias
Expand Down
8 changes: 5 additions & 3 deletions ui/views/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
version = "v0.0.1"
version = "v0.0.2"
HELP = "help"
)

Expand Down Expand Up @@ -54,8 +54,10 @@ func (h Help) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
fmt.Fprintln(h.view, fmt.Sprintf("lntop %s - (C) 2019 Edouard Paris", version))
fmt.Fprintln(h.view, "Released under the MIT License")
fmt.Fprintln(h.view, "")
fmt.Fprintln(h.view, fmt.Sprintf("%5s %s",
color.Cyan("F1 h:"), "show this help screen"))
fmt.Fprintln(h.view, fmt.Sprintf("%6s %s",
color.Cyan("F1 h:"), "show/close this help screen"))
fmt.Fprintln(h.view, fmt.Sprintf("%6s %s",
color.Cyan("F10 q:"), "quit"))
_, err = g.SetCurrentView(HELP)
return err
}
Expand Down

0 comments on commit d073bf2

Please sign in to comment.