aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-11-10 13:05:01 +0100
committerMichael Muré <batolettre@gmail.com>2019-11-10 13:05:01 +0100
commit965102f73c5a935bd35dde4ae27a187cdc5ad0ea (patch)
tree56fc681da23bf04edf359869a6efa3fbb9bdd621
parentcb8236c9c22007eb622b7219c58d3342f1f53d50 (diff)
downloadgit-bug-965102f73c5a935bd35dde4ae27a187cdc5ad0ea.tar.gz
termui: rework the cursor in bugtable to match the rendering before the switch to awesome-gocui
-rw-r--r--Gopkg.lock1
-rw-r--r--termui/bug_table.go34
2 files changed, 9 insertions, 26 deletions
diff --git a/Gopkg.lock b/Gopkg.lock
index 40f4fe63..a22bc9a9 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -495,6 +495,7 @@
"github.com/cheekybits/genny/generic",
"github.com/dustin/go-humanize",
"github.com/fatih/color",
+ "github.com/go-errors/errors",
"github.com/gorilla/mux",
"github.com/icrowley/fake",
"github.com/phayes/freeport",
diff --git a/termui/bug_table.go b/termui/bug_table.go
index ee02a167..41aa4e83 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -77,13 +77,8 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
}
v.Frame = false
- v.Highlight = true
v.SelBgColor = gocui.ColorWhite
v.SelFgColor = gocui.ColorBlack
-
- // restore the cursor
- // window is too small to set the cursor properly, ignoring the error
- _ = v.SetCursor(0, bt.selectCursor)
}
_, viewHeight := v.Size()
@@ -339,6 +334,8 @@ func (bt *bugTable) render(v *gocui.View, maxX int) {
lastEdit,
)
}
+
+ _ = v.SetHighlight(bt.selectCursor, true)
}
func (bt *bugTable) renderHeader(v *gocui.View, maxX int) {
@@ -360,10 +357,8 @@ func (bt *bugTable) renderFooter(v *gocui.View, maxX int) {
}
func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error {
- _, y := v.Cursor()
-
// If we are at the bottom of the page, switch to the next one.
- if y+1 > bt.getTableLength()-1 {
+ if bt.selectCursor+1 > bt.getTableLength()-1 {
_, max := v.Size()
if bt.pageCursor+max >= len(bt.allIds) {
@@ -372,24 +367,18 @@ func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error {
bt.pageCursor += max
bt.selectCursor = 0
- _ = v.SetCursor(0, bt.selectCursor)
return bt.doPaginate(max)
}
- y = minInt(y+1, bt.getTableLength()-1)
- // window is too small to set the cursor properly, ignoring the error
- _ = v.SetCursor(0, y)
- bt.selectCursor = y
+ bt.selectCursor = minInt(bt.selectCursor+1, bt.getTableLength()-1)
return nil
}
func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error {
- _, y := v.Cursor()
-
// If we are at the top of the page, switch to the previous one.
- if y-1 < 0 {
+ if bt.selectCursor-1 < 0 {
_, max := v.Size()
if bt.pageCursor == 0 {
@@ -398,27 +387,21 @@ func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error {
bt.pageCursor = maxInt(0, bt.pageCursor-max)
bt.selectCursor = max - 1
- _ = v.SetCursor(0, bt.selectCursor)
return bt.doPaginate(max)
}
- y = maxInt(y-1, 0)
- // window is too small to set the cursor properly, ignoring the error
- _ = v.SetCursor(0, y)
- bt.selectCursor = y
+ bt.selectCursor = maxInt(bt.selectCursor-1, 0)
return nil
}
func (bt *bugTable) cursorClamp(v *gocui.View) error {
- _, y := v.Cursor()
+ y := bt.selectCursor
y = minInt(y, bt.getTableLength()-1)
y = maxInt(y, 0)
- // window is too small to set the cursor properly, ignoring the error
- _ = v.SetCursor(0, y)
bt.selectCursor = y
return nil
@@ -453,8 +436,7 @@ func (bt *bugTable) newBug(g *gocui.Gui, v *gocui.View) error {
}
func (bt *bugTable) openBug(g *gocui.Gui, v *gocui.View) error {
- _, y := v.Cursor()
- id := bt.excerpts[y].Id
+ id := bt.excerpts[bt.selectCursor].Id
b, err := bt.repo.ResolveBug(id)
if err != nil {
return err