From 673eb4c49192b4bc96b7af0a053a52788dfa53be Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Wed, 20 Oct 2021 19:05:16 +0000 Subject: [PATCH 1/5] vim style vertical movement --- ui/keybindings.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/keybindings.go b/ui/keybindings.go index b17c489..56c5717 100644 --- a/ui/keybindings.go +++ b/ui/keybindings.go @@ -30,11 +30,21 @@ func setKeyBinding(c *controller, g *gocui.Gui) error { return err } + err = g.SetKeybinding("", 'k', gocui.ModNone, c.cursorUp) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, c.cursorDown) if err != nil { return err } + err = g.SetKeybinding("", 'j', gocui.ModNone, c.cursorDown) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyArrowLeft, gocui.ModNone, c.cursorLeft) if err != nil { return err From 204881e649cc0ec4413191c42152f5020def9475 Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Wed, 20 Oct 2021 19:58:24 +0000 Subject: [PATCH 2/5] vim/less style first/last line movement --- ui/keybindings.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/keybindings.go b/ui/keybindings.go index 56c5717..1f9ca08 100644 --- a/ui/keybindings.go +++ b/ui/keybindings.go @@ -60,11 +60,21 @@ func setKeyBinding(c *controller, g *gocui.Gui) error { return err } + err = g.SetKeybinding("", 'g', gocui.ModNone, c.cursorHome) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyEnd, gocui.ModNone, c.cursorEnd) if err != nil { return err } + err = g.SetKeybinding("", 'G', gocui.ModNone, c.cursorEnd) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyPgdn, gocui.ModNone, c.cursorPageDown) if err != nil { return err From 12c7114c3e0b83bb07c2c1184fdc4c7054a4053f Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Mon, 15 Nov 2021 20:40:56 +0000 Subject: [PATCH 3/5] RM: remove help panel --- ui/controller.go | 28 -------------- ui/keybindings.go | 10 ----- ui/views/channel.go | 3 +- ui/views/channels.go | 3 +- ui/views/help.go | 82 ---------------------------------------- ui/views/routing.go | 3 +- ui/views/transaction.go | 3 +- ui/views/transactions.go | 3 +- ui/views/views.go | 6 --- 9 files changed, 5 insertions(+), 136 deletions(-) delete mode 100644 ui/views/help.go diff --git a/ui/controller.go b/ui/controller.go index e7fa9b2..752a71a 100644 --- a/ui/controller.go +++ b/ui/controller.go @@ -182,36 +182,8 @@ func (c *controller) Listen(ctx context.Context, g *gocui.Gui, sub chan *events. } } -func (c *controller) Help(g *gocui.Gui, v *gocui.View) error { - maxX, maxY := g.Size() - view := c.views.Get(g.CurrentView()) - if view == nil { - return nil - } - - if view.Name() != views.HELP { - c.views.Main = view - return c.views.Help.Set(g, 0, -1, maxX, maxY) - } - - err := view.Delete(g) - if err != nil { - return err - } - - if c.views.Main != nil { - _, err := g.SetCurrentView(c.views.Main.Name()) - return err - } - - return nil -} - func (c *controller) Menu(g *gocui.Gui, v *gocui.View) error { maxX, maxY := g.Size() - if v.Name() == c.views.Help.Name() { - return nil - } if v.Name() != c.views.Menu.Name() { err := c.views.Menu.Set(g, 0, 6, 10, maxY) diff --git a/ui/keybindings.go b/ui/keybindings.go index 1f9ca08..5fc7356 100644 --- a/ui/keybindings.go +++ b/ui/keybindings.go @@ -90,16 +90,6 @@ func setKeyBinding(c *controller, g *gocui.Gui) error { return err } - err = g.SetKeybinding("", gocui.KeyF1, gocui.ModNone, c.Help) - if err != nil { - return err - } - - err = g.SetKeybinding("", 'h', gocui.ModNone, c.Help) - if err != nil { - return err - } - err = g.SetKeybinding("", gocui.KeyF2, gocui.ModNone, c.Menu) if err != nil { return err diff --git a/ui/views/channel.go b/ui/views/channel.go index cdbb6c0..0bd1965 100644 --- a/ui/views/channel.go +++ b/ui/views/channel.go @@ -96,8 +96,7 @@ func (c *Channel) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { footer.FgColor = gocui.ColorBlack footer.Clear() blackBg := color.Black(color.Background) - fmt.Fprintf(footer, "%s%s %s%s %s%s %s%s\n", - blackBg("F1"), "Help", + fmt.Fprintf(footer, "%s%s %s%s %s%s\n", blackBg("F2"), "Menu", blackBg("Enter"), "Channels", blackBg("F10"), "Quit", diff --git a/ui/views/channels.go b/ui/views/channels.go index f03ed4d..32534de 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -235,8 +235,7 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { footer.FgColor = gocui.ColorBlack footer.Clear() blackBg := color.Black(color.Background) - fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s", - blackBg("F1"), "Help", + fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s", blackBg("F2"), "Menu", blackBg("Enter"), "Channel", blackBg("F10"), "Quit", diff --git a/ui/views/help.go b/ui/views/help.go deleted file mode 100644 index 3a59e0a..0000000 --- a/ui/views/help.go +++ /dev/null @@ -1,82 +0,0 @@ -package views - -import ( - "fmt" - - "github.com/jroimartin/gocui" - - "github.com/edouardparis/lntop" - "github.com/edouardparis/lntop/ui/color" -) - -const ( - HELP = "help" -) - -type Help struct { - view *gocui.View -} - -func (h Help) Name() string { - return HELP -} - -func (h *Help) Wrap(v *gocui.View) View { - h.view = v - return h -} - -func (h Help) Delete(g *gocui.Gui) error { - return g.DeleteView(HELP) -} - -func (h Help) Origin() (int, int) { - return h.view.Origin() -} - -func (h Help) Cursor() (int, int) { - return h.view.Cursor() -} - -func (h Help) Speed() (int, int, int, int) { - return 1, 1, 1, 1 -} - -func (h Help) Limits() (pageSize int, fullSize int) { - _, pageSize = h.view.Size() - fullSize = len(h.view.BufferLines()) - 1 - return -} - -func (h *Help) SetCursor(x, y int) error { - return h.view.SetCursor(x, y) -} - -func (h *Help) SetOrigin(x, y int) error { - return h.view.SetOrigin(x, y) -} - -func (h Help) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { - var err error - h.view, err = g.SetView(HELP, x0-1, y0, x1, y1) - if err != nil { - if err != gocui.ErrUnknownView { - return err - } - } - h.view.Frame = false - cyan := color.Cyan() - fmt.Fprintf(h.view, "lntop %s - (C) 2019 Edouard Paris\n", lntop.Version) - fmt.Fprintln(h.view, "Released under the MIT License") - fmt.Fprintln(h.view, "") - fmt.Fprintf(h.view, "%6s show/close this help screen\n", cyan("F1 h:")) - fmt.Fprintf(h.view, "%6s show/close the menu sidebar\n", cyan("F2 m:")) - fmt.Fprintf(h.view, "%6s quit\n", cyan("F10 q:")) - fmt.Fprintln(h.view, "") - fmt.Fprintf(h.view, "%6s apply asc/desc order to the rows according to the selected column value\n", - cyan(" a d:")) - _, err = g.SetCurrentView(HELP) - return err -} - -func NewHelp() *Help { return &Help{} } diff --git a/ui/views/routing.go b/ui/views/routing.go index 44e84e0..518674f 100644 --- a/ui/views/routing.go +++ b/ui/views/routing.go @@ -216,8 +216,7 @@ func (c *Routing) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { footer.FgColor = gocui.ColorBlack footer.Clear() blackBg := color.Black(color.Background) - fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s", - blackBg("F1"), "Help", + fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s", blackBg("F2"), "Menu", blackBg("F10"), "Quit", )) diff --git a/ui/views/transaction.go b/ui/views/transaction.go index 62da79e..e33a2a2 100644 --- a/ui/views/transaction.go +++ b/ui/views/transaction.go @@ -95,8 +95,7 @@ func (c *Transaction) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { footer.FgColor = gocui.ColorBlack footer.Clear() blackBg := color.Black(color.Background) - fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s", - blackBg("F1"), "Help", + fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s", blackBg("F2"), "Menu", blackBg("Enter"), "Transactions", blackBg("F10"), "Quit", diff --git a/ui/views/transactions.go b/ui/views/transactions.go index c545f9d..47083b8 100644 --- a/ui/views/transactions.go +++ b/ui/views/transactions.go @@ -227,8 +227,7 @@ func (c *Transactions) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { footer.FgColor = gocui.ColorBlack footer.Clear() blackBg := color.Black(color.Background) - fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s", - blackBg("F1"), "Help", + fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s", blackBg("F2"), "Menu", blackBg("Enter"), "Transaction", blackBg("F10"), "Quit", diff --git a/ui/views/views.go b/ui/views/views.go index feda6ad..b6e922f 100644 --- a/ui/views/views.go +++ b/ui/views/views.go @@ -22,7 +22,6 @@ type View interface { type Views struct { Main View - Help *Help Header *Header Menu *Menu Summary *Summary @@ -40,8 +39,6 @@ func (v Views) Get(vi *gocui.View) View { switch vi.Name() { case CHANNELS: return v.Channels.Wrap(vi) - case HELP: - return v.Help.Wrap(vi) case MENU: return v.Menu.Wrap(vi) case CHANNEL: @@ -71,8 +68,6 @@ func (v *Views) Layout(g *gocui.Gui, maxX, maxY int) error { current := g.CurrentView() if current != nil { switch current.Name() { - case v.Help.Name(): - return nil case v.Menu.Name(): err = v.Menu.Set(g, 0, 6, 10, maxY) if err != nil { @@ -104,7 +99,6 @@ func New(cfg config.Views, m *models.Models) *Views { main := NewChannels(cfg.Channels, m.Channels) return &Views{ Header: NewHeader(m.Info), - Help: NewHelp(), Menu: NewMenu(), Summary: NewSummary(m.Info, m.ChannelsBalance, m.WalletBalance, m.Channels), Channels: main, From e4788bace8acadd5c41265c80f608f50f2fd49cc Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Mon, 15 Nov 2021 20:49:32 +0000 Subject: [PATCH 4/5] ADD: h/l for horizontal movement --- ui/keybindings.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/keybindings.go b/ui/keybindings.go index 5fc7356..cb2bd30 100644 --- a/ui/keybindings.go +++ b/ui/keybindings.go @@ -50,11 +50,21 @@ func setKeyBinding(c *controller, g *gocui.Gui) error { return err } + err = g.SetKeybinding("", 'h', gocui.ModNone, c.cursorLeft) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone, c.cursorRight) if err != nil { return err } + err = g.SetKeybinding("", 'l', gocui.ModNone, c.cursorRight) + if err != nil { + return err + } + err = g.SetKeybinding("", gocui.KeyHome, gocui.ModNone, c.cursorHome) if err != nil { return err From 261f50d7ea278c751c07b27268d43bc3ca33923c Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Mon, 15 Nov 2021 21:07:37 +0000 Subject: [PATCH 5/5] cleanup: if instead of switch-case with single case --- ui/views/views.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/views/views.go b/ui/views/views.go index b6e922f..611d21e 100644 --- a/ui/views/views.go +++ b/ui/views/views.go @@ -67,8 +67,7 @@ func (v *Views) Layout(g *gocui.Gui, maxX, maxY int) error { current := g.CurrentView() if current != nil { - switch current.Name() { - case v.Menu.Name(): + if current.Name() == v.Menu.Name() { err = v.Menu.Set(g, 0, 6, 10, maxY) if err != nil { return err