aboutsummaryrefslogtreecommitdiffstats
path: root/termui
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 /termui
parentcb8236c9c22007eb622b7219c58d3342f1f53d50 (diff)
downloadgit-bug-965102f73c5a935bd35dde4ae27a187cdc5ad0ea.tar.gz
termui: rework the cursor in bugtable to match the rendering before the switch to awesome-gocui
Diffstat (limited to 'termui')
-rw-r--r--termui/bug_table.go34
1 files changed, 8 insertions, 26 deletions
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