From 8349400806b4fe41f5e139b252f54c949a3c068f Mon Sep 17 00:00:00 2001 From: Simon Let Date: Mon, 4 May 2020 17:04:00 +0200 Subject: [PATCH] status fixes, ctrl+pn works as arrow keys --- cmd/cli/main.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index ca37a95..4e9f9ce 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -124,9 +124,15 @@ func runReshCli() (string, int) { if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, layout.Next); err != nil { log.Panicln(err) } + if err := g.SetKeybinding("", gocui.KeyCtrlN, gocui.ModNone, layout.Next); err != nil { + log.Panicln(err) + } if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, layout.Prev); err != nil { log.Panicln(err) } + if err := g.SetKeybinding("", gocui.KeyCtrlP, gocui.ModNone, layout.Prev); err != nil { + log.Panicln(err) + } if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) } @@ -448,6 +454,9 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { } } + if m.s.highlightedItem >= len(m.s.data) { + m.s.highlightedItem = len(m.s.data) - 1 + } // status line topBoxSize := 3 // size of the query box up top realLineLength := maxX - 2 @@ -457,15 +466,16 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { m.s.displayedItemsCount = maxY - topBoxSize - selectedLineCount - for i, itm := range data { - if i == maxY-topBoxSize-selectedLineCount { - if debug { - log.Println(maxY) - } + var index int + for index < len(data) { + itm := data[index] + if index == maxY-topBoxSize-selectedLineCount { + // page is full break } + displayStr, _ := itm.produceLine(longestDateLen, longestFlagsLen, true) - if m.s.highlightedItem == i { + if m.s.highlightedItem == index { // maxX * 2 because there are escape sequences that make it hard to tell the real string lenght displayStr = doHighlightString(displayStr, maxX*2) if debug { @@ -482,9 +492,12 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { } } v.WriteString(displayStr + "\n") - // if m.s.highlightedItem == i { - // v.SetHighlight(m.s.highlightedItem, true) - // } + index++ + } + // push the status line to the bottom of the page + for index < maxY-topBoxSize-selectedLineCount { + v.WriteString("\n") + index++ } // status line var idxSt, idxEnd int