diff --git a/cli/cli.go b/cli/cli.go index 2df2ae6..ac25280 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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 { diff --git a/ui/controller.go b/ui/controller.go index e0cf8a5..519de62 100644 --- a/ui/controller.go +++ b/ui/controller.go @@ -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 } @@ -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 @@ -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 } diff --git a/ui/models/channels.go b/ui/models/channels.go index 71b95db..fac7d07 100644 --- a/ui/models/channels.go +++ b/ui/models/channels.go @@ -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 diff --git a/ui/models/models.go b/ui/models/models.go index 6864b2b..4b17e1d 100644 --- a/ui/models/models.go +++ b/ui/models/models.go @@ -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)) } } diff --git a/ui/views/channel.go b/ui/views/channel.go index f87f734..09755c5 100644 --- a/ui/views/channel.go +++ b/ui/views/channel.go @@ -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 diff --git a/ui/views/channels.go b/ui/views/channels.go index 3ca6d91..a235d8e 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -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 } @@ -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) } @@ -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 diff --git a/ui/views/help.go b/ui/views/help.go index 58bdc60..9f0f36c 100644 --- a/ui/views/help.go +++ b/ui/views/help.go @@ -9,7 +9,7 @@ import ( ) const ( - version = "v0.0.1" + version = "v0.0.2" HELP = "help" ) @@ -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 }