aboutsummaryrefslogtreecommitdiffstats
path: root/termui/bug_table.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-31 22:19:11 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-31 22:19:11 +0200
commit6b012b1e485d369d82cb410a1652f53a752bf21c (patch)
treeb8f882bda85bf8b072fce3b6830f91cbf0a01e1c /termui/bug_table.go
parent20bd25f332a5ca04ee80a8a4965f56ef3e7cdbf2 (diff)
downloadgit-bug-6b012b1e485d369d82cb410a1652f53a752bf21c.tar.gz
termui: add a reusable error popup, use it for badly formated bug creation
Diffstat (limited to 'termui/bug_table.go')
-rw-r--r--termui/bug_table.go40
1 files changed, 22 insertions, 18 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 264dff2d..7f96df02 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -27,6 +27,11 @@ func newBugTable(cache cache.RepoCacher) *bugTable {
func (bt *bugTable) layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
+ if maxY < 4 {
+ // window too small !
+ return nil
+ }
+
v, err := g.SetView("header", -1, -1, maxX, 3)
if err != nil {
@@ -51,12 +56,6 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Highlight = true
v.SelBgColor = gocui.ColorWhite
v.SelFgColor = gocui.ColorBlack
-
- _, err = g.SetCurrentView(bugTableView)
-
- if err != nil {
- return err
- }
}
_, viewHeight := v.Size()
@@ -99,6 +98,12 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
fmt.Fprintf(v, "[q] Quit [←,h] Previous page [↓,j] Down [↑,k] Up [→,l] Next page [enter] Open bug [n] New bug")
}
+ _, err = g.SetCurrentView(bugTableView)
+
+ if err != nil {
+ return err
+ }
+
return nil
}
@@ -181,6 +186,11 @@ func (bt *bugTable) doPaginate(allIds []string, max int) error {
nb := minInt(len(allIds)-bt.cursor, max)
+ if nb < 0 {
+ bt.bugs = []*bug.Snapshot{}
+ return nil
+ }
+
// slice the data
ids := allIds[bt.cursor : bt.cursor+nb]
@@ -260,10 +270,8 @@ func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error {
_, y := v.Cursor()
y = minInt(y+1, bt.getTableLength()-1)
- err := v.SetCursor(0, y)
- if err != nil {
- return err
- }
+ // window is too small to set the cursor properly, ignoring the error
+ _ = v.SetCursor(0, y)
return nil
}
@@ -272,10 +280,8 @@ func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error {
_, y := v.Cursor()
y = maxInt(y-1, 0)
- err := v.SetCursor(0, y)
- if err != nil {
- return err
- }
+ // window is too small to set the cursor properly, ignoring the error
+ _ = v.SetCursor(0, y)
return nil
}
@@ -286,10 +292,8 @@ func (bt *bugTable) cursorClamp(v *gocui.View) error {
y = minInt(y, bt.getTableLength()-1)
y = maxInt(y, 0)
- err := v.SetCursor(0, y)
- if err != nil {
- return err
- }
+ // window is too small to set the cursor properly, ignoring the error
+ _ = v.SetCursor(0, y)
return nil
}