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

Merge pull request #45 from juhi24/vim

Vim style vertical movement
This commit is contained in:
Edouard 2021-11-16 10:42:20 +01:00 committed by GitHub
commit 650f1420d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 138 deletions

View File

@ -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)

View File

@ -30,31 +30,61 @@ 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
}
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
}
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
@ -70,16 +100,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

View File

@ -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",

View File

@ -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",

View File

@ -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{} }

View File

@ -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",
))

View File

@ -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",

View File

@ -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",

View File

@ -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:
@ -70,10 +67,7 @@ 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():
if current.Name() == v.Menu.Name() {
err = v.Menu.Set(g, 0, 6, 10, maxY)
if err != nil {
return err
@ -104,7 +98,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,