aboutsummaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-11-10 13:14:42 +0100
committerGitHub <noreply@github.com>2019-11-10 13:14:42 +0100
commiteaf963164cad17f87999f8a781ff9b688729b31c (patch)
tree68ecd87689ee16ad3de5a0e77dc13ad618fb6962 /termui
parent318039df31b0846de85e6469d75c3fd5fe5a00a1 (diff)
parent965102f73c5a935bd35dde4ae27a187cdc5ad0ea (diff)
downloadgit-bug-eaf963164cad17f87999f8a781ff9b688729b31c.tar.gz
Merge pull request #242 from MichaelMure/gocui
termui: migrate to awesome-gocui instead of the old fork I had
Diffstat (limited to 'termui')
-rw-r--r--termui/bug_table.go60
-rw-r--r--termui/input_popup.go6
-rw-r--r--termui/label_select.go16
-rw-r--r--termui/msg_popup.go6
-rw-r--r--termui/show_bug.go24
-rw-r--r--termui/termui.go10
6 files changed, 54 insertions, 68 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index c432c94a..41aa4e83 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -7,7 +7,7 @@ import (
"time"
"github.com/MichaelMure/go-term-text"
- "github.com/MichaelMure/gocui"
+ "github.com/awesome-gocui/gocui"
"github.com/dustin/go-humanize"
"github.com/MichaelMure/git-bug/cache"
@@ -56,10 +56,10 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
return nil
}
- v, err := g.SetView(bugTableHeaderView, -1, -1, maxX, 3)
+ v, err := g.SetView(bugTableHeaderView, -1, -1, maxX, 3, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -69,21 +69,16 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Clear()
bt.renderHeader(v, maxX)
- v, err = g.SetView(bugTableView, -1, 1, maxX, maxY-3)
+ v, err = g.SetView(bugTableView, -1, 1, maxX, maxY-3, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
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()
@@ -100,10 +95,10 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Clear()
bt.render(v, maxX)
- v, err = g.SetView(bugTableFooterView, -1, maxY-4, maxX, maxY)
+ v, err = g.SetView(bugTableFooterView, -1, maxY-4, maxX, maxY, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -113,10 +108,10 @@ func (bt *bugTable) layout(g *gocui.Gui) error {
v.Clear()
bt.renderFooter(v, maxX)
- v, err = g.SetView(bugTableInstructionView, -1, maxY-2, maxX, maxY)
+ v, err = g.SetView(bugTableInstructionView, -1, maxY-2, maxX, maxY, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -216,16 +211,16 @@ func (bt *bugTable) keybindings(g *gocui.Gui) error {
}
func (bt *bugTable) disable(g *gocui.Gui) error {
- if err := g.DeleteView(bugTableView); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(bugTableView); err != nil && !gocui.IsUnknownView(err) {
return err
}
- if err := g.DeleteView(bugTableHeaderView); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(bugTableHeaderView); err != nil && !gocui.IsUnknownView(err) {
return err
}
- if err := g.DeleteView(bugTableFooterView); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(bugTableFooterView); err != nil && !gocui.IsUnknownView(err) {
return err
}
- if err := g.DeleteView(bugTableInstructionView); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(bugTableInstructionView); err != nil && !gocui.IsUnknownView(err) {
return err
}
return nil
@@ -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
diff --git a/termui/input_popup.go b/termui/input_popup.go
index 3576ba2f..3ff9b5bf 100644
--- a/termui/input_popup.go
+++ b/termui/input_popup.go
@@ -3,7 +3,7 @@ package termui
import (
"io/ioutil"
- "github.com/MichaelMure/gocui"
+ "github.com/awesome-gocui/gocui"
)
const inputPopupView = "inputPopupView"
@@ -46,9 +46,9 @@ func (ip *inputPopup) layout(g *gocui.Gui) error {
x0 := (maxX - width) / 2
y0 := (maxY - height) / 2
- v, err := g.SetView(inputPopupView, x0, y0, x0+width, y0+height)
+ v, err := g.SetView(inputPopupView, x0, y0, x0+width, y0+height, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
diff --git a/termui/label_select.go b/termui/label_select.go
index 39edbdb1..a05d9c8b 100644
--- a/termui/label_select.go
+++ b/termui/label_select.go
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
- "github.com/MichaelMure/gocui"
+ "github.com/awesome-gocui/gocui"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
@@ -106,9 +106,9 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
x0 := 1
y0 := 0 - ls.scroll
- v, err := g.SetView(labelSelectView, x0, 0, x0+width, maxY-2)
+ v, err := g.SetView(labelSelectView, x0, 0, x0+width, maxY-2, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -117,8 +117,8 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
for i, label := range ls.labels {
viewname := fmt.Sprintf("view%d", i)
- v, err := g.SetView(viewname, x0+2, y0, x0+width-2, y0+2)
- if err != nil && err != gocui.ErrUnknownView {
+ v, err := g.SetView(viewname, x0+2, y0, x0+width-2, y0+2, 0)
+ if err != nil && !gocui.IsUnknownView(err) {
return err
}
ls.childViews = append(ls.childViews, viewname)
@@ -137,10 +137,10 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
y0 += 2
}
- v, err = g.SetView(labelSelectInstructionsView, -1, maxY-2, maxX, maxY)
+ v, err = g.SetView(labelSelectInstructionsView, -1, maxY-2, maxX, maxY, 0)
ls.childViews = append(ls.childViews, labelSelectInstructionsView)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
v.Frame = false
@@ -159,7 +159,7 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
func (ls *labelSelect) disable(g *gocui.Gui) error {
for _, view := range ls.childViews {
- if err := g.DeleteView(view); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(view); err != nil && !gocui.IsUnknownView(err) {
return err
}
}
diff --git a/termui/msg_popup.go b/termui/msg_popup.go
index 99180c99..236c16a2 100644
--- a/termui/msg_popup.go
+++ b/termui/msg_popup.go
@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/MichaelMure/go-term-text"
- "github.com/MichaelMure/gocui"
+ "github.com/awesome-gocui/gocui"
)
const msgPopupView = "msgPopupView"
@@ -50,9 +50,9 @@ func (ep *msgPopup) layout(g *gocui.Gui) error {
x0 := (maxX - width) / 2
y0 := (maxY - height) / 2
- v, err := g.SetView(msgPopupView, x0, y0, x0+width, y0+height)
+ v, err := g.SetView(msgPopupView, x0, y0, x0+width, y0+height, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 50478b8f..6c7163ac 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -6,7 +6,7 @@ import (
"strings"
"github.com/MichaelMure/go-term-text"
- "github.com/MichaelMure/gocui"
+ "github.com/awesome-gocui/gocui"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
@@ -49,10 +49,10 @@ func (sb *showBug) layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
sb.childViews = nil
- v, err := g.SetView(showBugView, 0, 0, maxX*2/3, maxY-2)
+ v, err := g.SetView(showBugView, 0, 0, maxX*2/3, maxY-2, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -66,10 +66,10 @@ func (sb *showBug) layout(g *gocui.Gui) error {
return err
}
- v, err = g.SetView(showBugSidebarView, maxX*2/3+1, 0, maxX-1, maxY-2)
+ v, err = g.SetView(showBugSidebarView, maxX*2/3+1, 0, maxX-1, maxY-2, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -83,10 +83,10 @@ func (sb *showBug) layout(g *gocui.Gui) error {
return err
}
- v, err = g.SetView(showBugInstructionView, -1, maxY-2, maxX, maxY)
+ v, err = g.SetView(showBugInstructionView, -1, maxY-2, maxX, maxY, 0)
if err != nil {
- if err != gocui.ErrUnknownView {
+ if !gocui.IsUnknownView(err) {
return err
}
@@ -190,7 +190,7 @@ func (sb *showBug) keybindings(g *gocui.Gui) error {
func (sb *showBug) disable(g *gocui.Gui) error {
for _, view := range sb.childViews {
- if err := g.DeleteView(view); err != nil && err != gocui.ErrUnknownView {
+ if err := g.DeleteView(view); err != nil && !gocui.IsUnknownView(err) {
return err
}
}
@@ -383,9 +383,9 @@ func emptyMessagePlaceholder() string {
}
func (sb *showBug) createOpView(g *gocui.Gui, name string, x0 int, y0 int, maxX int, height int, selectable bool) (*gocui.View, error) {
- v, err := g.SetView(name, x0, y0, maxX, y0+height+1)
+ v, err := g.SetView(name, x0, y0, maxX, y0+height+1, 0)
- if err != nil && err != gocui.ErrUnknownView {
+ if err != nil && !gocui.IsUnknownView(err) {
return nil, err
}
@@ -403,9 +403,9 @@ func (sb *showBug) createOpView(g *gocui.Gui, name string, x0 int, y0 int, maxX
}
func (sb *showBug) createSideView(g *gocui.Gui, name string, x0 int, y0 int, maxX int, height int) (*gocui.View, error) {
- v, err := g.SetView(name, x0, y0, maxX, y0+height+1)
+ v, err := g.SetView(name, x0, y0, maxX, y0+height+1, 0)
- if err != nil && err != gocui.ErrUnknownView {
+ if err != nil && !gocui.IsUnknownView(err) {
return nil, err
}
diff --git a/termui/termui.go b/termui/termui.go
index 8aece020..67f91280 100644
--- a/termui/termui.go
+++ b/termui/termui.go
@@ -2,9 +2,13 @@
package termui
import (
- "github.com/MichaelMure/gocui"
+ "fmt"
+
+ "github.com/awesome-gocui/gocui"
"github.com/pkg/errors"
+ errors2 "github.com/go-errors/errors"
+
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/input"
@@ -63,15 +67,15 @@ func Run(cache *cache.RepoCache) error {
err := <-ui.gError
if err != nil && err != gocui.ErrQuit {
+ fmt.Println(err.(*errors2.Error).ErrorStack())
return err
}
-
return nil
}
func initGui(action func(ui *termUI) error) {
- g, err := gocui.NewGui(gocui.Output256)
+ g, err := gocui.NewGui(gocui.Output256, false)
if err != nil {
ui.gError <- err