2018-07-30 18:00:10 +03:00
|
|
|
package termui
|
|
|
|
|
|
|
|
import (
|
2018-08-12 22:09:30 +03:00
|
|
|
"bytes"
|
2018-07-30 18:00:10 +03:00
|
|
|
"fmt"
|
2019-11-03 16:00:35 +03:00
|
|
|
"strings"
|
2018-08-12 22:09:30 +03:00
|
|
|
|
2020-07-01 21:00:53 +03:00
|
|
|
text "github.com/MichaelMure/go-term-text"
|
2019-11-03 22:47:29 +03:00
|
|
|
"github.com/awesome-gocui/gocui"
|
2019-11-03 16:00:35 +03:00
|
|
|
"github.com/dustin/go-humanize"
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2019-03-27 23:44:11 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2020-03-14 18:47:38 +03:00
|
|
|
"github.com/MichaelMure/git-bug/query"
|
2018-09-11 23:04:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/colors"
|
2018-07-30 18:00:10 +03:00
|
|
|
)
|
|
|
|
|
2018-07-31 17:43:43 +03:00
|
|
|
const bugTableView = "bugTableView"
|
2018-08-01 03:15:40 +03:00
|
|
|
const bugTableHeaderView = "bugTableHeaderView"
|
|
|
|
const bugTableFooterView = "bugTableFooterView"
|
|
|
|
const bugTableInstructionView = "bugTableInstructionView"
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-09-11 20:28:32 +03:00
|
|
|
const defaultRemote = "origin"
|
|
|
|
const defaultQuery = "status:open"
|
2018-08-12 22:09:30 +03:00
|
|
|
|
2020-04-12 12:11:01 +03:00
|
|
|
var bugTableHelp = helpBar{
|
|
|
|
{"q", "Quit"},
|
|
|
|
{"s", "Search"},
|
|
|
|
{"←↓↑→,hjkl", "Navigation"},
|
|
|
|
{"↵", "Open bug"},
|
|
|
|
{"n", "New bug"},
|
|
|
|
{"i", "Pull"},
|
|
|
|
{"o", "Push"},
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
type bugTable struct {
|
2018-08-23 22:24:57 +03:00
|
|
|
repo *cache.RepoCache
|
2018-09-11 20:28:32 +03:00
|
|
|
queryStr string
|
2020-03-22 15:53:34 +03:00
|
|
|
query *query.Query
|
2019-08-12 17:12:14 +03:00
|
|
|
allIds []entity.Id
|
2019-04-21 01:55:39 +03:00
|
|
|
excerpts []*cache.BugExcerpt
|
2018-08-01 03:15:40 +03:00
|
|
|
pageCursor int
|
|
|
|
selectCursor int
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-09-09 21:21:49 +03:00
|
|
|
func newBugTable(c *cache.RepoCache) *bugTable {
|
2020-03-14 18:47:38 +03:00
|
|
|
q, err := query.Parse(defaultQuery)
|
2018-09-11 20:28:32 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
return &bugTable{
|
2018-09-11 20:28:32 +03:00
|
|
|
repo: c,
|
2020-03-14 18:47:38 +03:00
|
|
|
query: q,
|
2018-09-11 20:28:32 +03:00
|
|
|
queryStr: defaultQuery,
|
2018-08-01 03:15:40 +03:00
|
|
|
pageCursor: 0,
|
|
|
|
selectCursor: 0,
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) layout(g *gocui.Gui) error {
|
|
|
|
maxX, maxY := g.Size()
|
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
if maxY < 4 {
|
|
|
|
// window too small !
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-15 13:38:24 +03:00
|
|
|
v, err := g.SetView(bugTableHeaderView, -1, -1, maxX, 1, 0)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2019-11-03 22:47:29 +03:00
|
|
|
if !gocui.IsUnknownView(err) {
|
2018-07-30 18:00:10 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2018-07-31 17:43:43 +03:00
|
|
|
bt.renderHeader(v, maxX)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
2020-08-30 13:17:04 +03:00
|
|
|
v, err = g.SetView(bugTableView, -1, 0, maxX, maxY-3, 0)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2019-11-03 22:47:29 +03:00
|
|
|
if !gocui.IsUnknownView(err) {
|
2018-07-30 18:00:10 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
|
|
|
v.SelBgColor = gocui.ColorWhite
|
|
|
|
v.SelFgColor = gocui.ColorBlack
|
|
|
|
}
|
|
|
|
|
2020-07-15 13:38:24 +03:00
|
|
|
viewWidth, viewHeight := v.Size()
|
2018-07-31 23:30:50 +03:00
|
|
|
err = bt.paginate(viewHeight)
|
2018-07-31 17:43:43 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = bt.cursorClamp(v)
|
2018-07-30 18:00:10 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2020-07-15 13:38:24 +03:00
|
|
|
bt.render(v, viewWidth)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
2020-08-30 13:17:04 +03:00
|
|
|
v, err = g.SetView(bugTableFooterView, -1, maxY-4, maxX, maxY, 0)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2019-11-03 22:47:29 +03:00
|
|
|
if !gocui.IsUnknownView(err) {
|
2018-07-30 18:00:10 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2018-07-31 17:43:43 +03:00
|
|
|
bt.renderFooter(v, maxX)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err = g.SetView(bugTableInstructionView, -1, maxY-2, maxX, maxY, 0)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2019-11-03 22:47:29 +03:00
|
|
|
if !gocui.IsUnknownView(err) {
|
2018-07-30 18:00:10 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
2020-07-13 14:27:09 +03:00
|
|
|
v.FgColor = gocui.ColorWhite
|
2018-07-31 17:43:43 +03:00
|
|
|
}
|
2020-08-30 13:17:04 +03:00
|
|
|
v.Clear()
|
|
|
|
bt.renderHelp(v, maxX)
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
_, err = g.SetCurrentView(bugTableView)
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
2018-07-31 17:43:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) keybindings(g *gocui.Gui) error {
|
|
|
|
// Quit
|
2018-09-13 18:55:55 +03:00
|
|
|
if err := g.SetKeybinding(bugTableView, 'q', gocui.ModNone, quit); err != nil {
|
2018-07-31 17:43:43 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Down
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'j', gocui.ModNone,
|
|
|
|
bt.cursorDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyArrowDown, gocui.ModNone,
|
|
|
|
bt.cursorDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Up
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'k', gocui.ModNone,
|
|
|
|
bt.cursorUp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyArrowUp, gocui.ModNone,
|
|
|
|
bt.cursorUp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Previous page
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'h', gocui.ModNone,
|
|
|
|
bt.previousPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyArrowLeft, gocui.ModNone,
|
|
|
|
bt.previousPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyPgup, gocui.ModNone,
|
|
|
|
bt.previousPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Next page
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'l', gocui.ModNone,
|
|
|
|
bt.nextPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyArrowRight, gocui.ModNone,
|
|
|
|
bt.nextPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyPgdn, gocui.ModNone,
|
|
|
|
bt.nextPage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// New bug
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'n', gocui.ModNone,
|
2018-08-02 17:35:13 +03:00
|
|
|
bt.newBug); err != nil {
|
2018-07-31 17:43:43 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
// Open bug
|
|
|
|
if err := g.SetKeybinding(bugTableView, gocui.KeyEnter, gocui.ModNone,
|
|
|
|
bt.openBug); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-12 22:09:30 +03:00
|
|
|
// Pull
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'i', gocui.ModNone,
|
|
|
|
bt.pull); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'o', gocui.ModNone,
|
|
|
|
bt.push); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-11 20:28:32 +03:00
|
|
|
// Query
|
2018-09-13 18:55:55 +03:00
|
|
|
if err := g.SetKeybinding(bugTableView, 's', gocui.ModNone,
|
2018-09-11 20:28:32 +03:00
|
|
|
bt.changeQuery); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) disable(g *gocui.Gui) error {
|
2019-11-03 22:47:29 +03:00
|
|
|
if err := g.DeleteView(bugTableView); err != nil && !gocui.IsUnknownView(err) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2019-11-03 22:47:29 +03:00
|
|
|
if err := g.DeleteView(bugTableHeaderView); err != nil && !gocui.IsUnknownView(err) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2019-11-03 22:47:29 +03:00
|
|
|
if err := g.DeleteView(bugTableFooterView); err != nil && !gocui.IsUnknownView(err) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2019-11-03 22:47:29 +03:00
|
|
|
if err := g.DeleteView(bugTableInstructionView); err != nil && !gocui.IsUnknownView(err) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2018-07-31 17:43:43 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) paginate(max int) error {
|
2020-12-08 16:42:13 +03:00
|
|
|
var err error
|
|
|
|
bt.allIds, err = bt.repo.QueryBugs(bt.query)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
return bt.doPaginate(max)
|
2018-07-31 17:43:43 +03:00
|
|
|
}
|
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
func (bt *bugTable) doPaginate(max int) error {
|
2018-07-31 17:43:43 +03:00
|
|
|
// clamp the cursor
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.pageCursor = maxInt(bt.pageCursor, 0)
|
2018-09-02 16:46:43 +03:00
|
|
|
bt.pageCursor = minInt(bt.pageCursor, len(bt.allIds))
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
nb := minInt(len(bt.allIds)-bt.pageCursor, max)
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
if nb < 0 {
|
2019-04-21 01:55:39 +03:00
|
|
|
bt.excerpts = []*cache.BugExcerpt{}
|
2018-07-31 23:19:11 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-31 17:43:43 +03:00
|
|
|
// slice the data
|
2018-09-02 16:46:43 +03:00
|
|
|
ids := bt.allIds[bt.pageCursor : bt.pageCursor+nb]
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2019-04-21 01:55:39 +03:00
|
|
|
bt.excerpts = make([]*cache.BugExcerpt, len(ids))
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
for i, id := range ids {
|
2019-04-21 01:55:39 +03:00
|
|
|
excerpt, err := bt.repo.ResolveBugExcerpt(id)
|
2018-07-31 17:43:43 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-21 01:55:39 +03:00
|
|
|
bt.excerpts[i] = excerpt
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) getTableLength() int {
|
2019-04-21 01:55:39 +03:00
|
|
|
return len(bt.excerpts)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-07-30 19:09:44 +03:00
|
|
|
func (bt *bugTable) getColumnWidths(maxX int) map[string]int {
|
|
|
|
m := make(map[string]int)
|
2020-07-15 15:27:23 +03:00
|
|
|
m["id"] = 7
|
|
|
|
m["status"] = 6
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2018-08-02 17:48:07 +03:00
|
|
|
left := maxX - 5 - m["id"] - m["status"]
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2020-07-15 15:27:23 +03:00
|
|
|
m["comments"] = 3
|
2019-10-15 13:25:44 +03:00
|
|
|
left -= m["comments"]
|
2020-07-15 15:27:23 +03:00
|
|
|
m["lastEdit"] = 14
|
2018-08-02 17:48:07 +03:00
|
|
|
left -= m["lastEdit"]
|
|
|
|
|
2018-09-26 23:03:58 +03:00
|
|
|
m["author"] = minInt(maxInt(left/3, 15), 10+left/8)
|
2018-07-30 19:09:44 +03:00
|
|
|
m["title"] = maxInt(left-m["author"], 10)
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
func (bt *bugTable) render(v *gocui.View, maxX int) {
|
2018-07-30 19:09:44 +03:00
|
|
|
columnWidths := bt.getColumnWidths(maxX)
|
|
|
|
|
2019-04-21 01:55:39 +03:00
|
|
|
for _, excerpt := range bt.excerpts {
|
2020-08-30 12:30:57 +03:00
|
|
|
summaryTxt := fmt.Sprintf("%3d", excerpt.LenComments-1)
|
|
|
|
if excerpt.LenComments-1 <= 0 {
|
2019-11-03 16:00:35 +03:00
|
|
|
summaryTxt = ""
|
|
|
|
}
|
2020-08-30 12:30:57 +03:00
|
|
|
if excerpt.LenComments-1 > 999 {
|
2020-07-15 15:27:23 +03:00
|
|
|
summaryTxt = " ∞"
|
2019-10-17 00:51:11 +03:00
|
|
|
}
|
2019-10-15 13:25:44 +03:00
|
|
|
|
2019-11-03 16:00:35 +03:00
|
|
|
var labelsTxt strings.Builder
|
2020-08-30 13:17:04 +03:00
|
|
|
for _, l := range excerpt.Labels {
|
2020-07-15 15:27:23 +03:00
|
|
|
labelsTxt.WriteString(" ")
|
2020-08-30 13:17:04 +03:00
|
|
|
lc256 := l.Color().Term256()
|
|
|
|
labelsTxt.WriteString(lc256.Escape())
|
|
|
|
labelsTxt.WriteString("◼")
|
|
|
|
labelsTxt.WriteString(lc256.Unescape())
|
2019-10-15 13:25:44 +03:00
|
|
|
}
|
2018-12-01 19:09:13 +03:00
|
|
|
|
2020-07-01 21:00:53 +03:00
|
|
|
author, err := bt.repo.ResolveIdentityExcerpt(excerpt.AuthorId)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2019-04-21 01:55:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-15 13:38:24 +03:00
|
|
|
id := text.LeftPadMaxLine(excerpt.Id.Human(), columnWidths["id"], 0)
|
2020-07-15 15:27:23 +03:00
|
|
|
status := text.LeftPadMaxLine(excerpt.Status.String(), columnWidths["status"], 0)
|
2019-11-03 16:00:35 +03:00
|
|
|
labels := text.TruncateMax(labelsTxt.String(), minInt(columnWidths["title"]-2, 10))
|
2020-07-15 15:27:23 +03:00
|
|
|
title := text.LeftPadMaxLine(strings.TrimSpace(excerpt.Title), columnWidths["title"]-text.Len(labels), 0)
|
2020-07-01 21:00:53 +03:00
|
|
|
authorTxt := text.LeftPadMaxLine(author.DisplayName(), columnWidths["author"], 0)
|
2020-07-15 15:27:23 +03:00
|
|
|
comments := text.LeftPadMaxLine(summaryTxt, columnWidths["comments"], 0)
|
2020-07-01 21:00:53 +03:00
|
|
|
lastEdit := text.LeftPadMaxLine(humanize.Time(excerpt.EditTime()), columnWidths["lastEdit"], 1)
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2019-11-03 16:00:35 +03:00
|
|
|
_, _ = fmt.Fprintf(v, "%s %s %s%s %s %s %s\n",
|
2018-09-11 23:04:16 +03:00
|
|
|
colors.Cyan(id),
|
|
|
|
colors.Yellow(status),
|
2018-08-08 23:21:02 +03:00
|
|
|
title,
|
2019-11-03 16:00:35 +03:00
|
|
|
labels,
|
2020-07-01 21:00:53 +03:00
|
|
|
colors.Magenta(authorTxt),
|
2019-10-15 13:25:44 +03:00
|
|
|
comments,
|
2018-08-08 23:21:02 +03:00
|
|
|
lastEdit,
|
|
|
|
)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
2019-11-10 15:05:01 +03:00
|
|
|
|
|
|
|
_ = v.SetHighlight(bt.selectCursor, true)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) renderHeader(v *gocui.View, maxX int) {
|
2018-07-30 19:09:44 +03:00
|
|
|
columnWidths := bt.getColumnWidths(maxX)
|
|
|
|
|
2020-07-15 13:38:24 +03:00
|
|
|
id := text.LeftPadMaxLine("ID", columnWidths["id"], 0)
|
2020-07-15 15:27:23 +03:00
|
|
|
status := text.LeftPadMaxLine("STATUS", columnWidths["status"], 0)
|
|
|
|
title := text.LeftPadMaxLine("TITLE", columnWidths["title"], 0)
|
|
|
|
author := text.LeftPadMaxLine("AUTHOR", columnWidths["author"], 0)
|
|
|
|
comments := text.LeftPadMaxLine("CMT", columnWidths["comments"], 0)
|
2018-12-01 19:09:13 +03:00
|
|
|
lastEdit := text.LeftPadMaxLine("LAST EDIT", columnWidths["lastEdit"], 1)
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2019-10-15 13:25:44 +03:00
|
|
|
_, _ = fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, comments, lastEdit)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) renderFooter(v *gocui.View, maxX int) {
|
2020-08-30 13:17:04 +03:00
|
|
|
_, _ = fmt.Fprintf(v, " \nShowing %d of %d bugs", len(bt.excerpts), len(bt.allIds))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) renderHelp(v *gocui.View, maxX int) {
|
|
|
|
_, _ = fmt.Fprint(v, bugTableHelp.Render(maxX))
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-07-31 17:43:43 +03:00
|
|
|
func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error {
|
2018-12-22 02:06:40 +03:00
|
|
|
// If we are at the bottom of the page, switch to the next one.
|
2019-11-10 15:05:01 +03:00
|
|
|
if bt.selectCursor+1 > bt.getTableLength()-1 {
|
2018-12-23 23:16:27 +03:00
|
|
|
_, max := v.Size()
|
|
|
|
|
|
|
|
if bt.pageCursor+max >= len(bt.allIds) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
bt.pageCursor += max
|
|
|
|
bt.selectCursor = 0
|
|
|
|
|
|
|
|
return bt.doPaginate(max)
|
2018-12-22 02:06:40 +03:00
|
|
|
}
|
|
|
|
|
2019-11-10 15:05:01 +03:00
|
|
|
bt.selectCursor = minInt(bt.selectCursor+1, bt.getTableLength()-1)
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error {
|
2018-12-22 02:06:40 +03:00
|
|
|
// If we are at the top of the page, switch to the previous one.
|
2019-11-10 15:05:01 +03:00
|
|
|
if bt.selectCursor-1 < 0 {
|
2018-12-23 23:16:27 +03:00
|
|
|
_, max := v.Size()
|
|
|
|
|
|
|
|
if bt.pageCursor == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
bt.pageCursor = maxInt(0, bt.pageCursor-max)
|
|
|
|
bt.selectCursor = max - 1
|
|
|
|
|
|
|
|
return bt.doPaginate(max)
|
2018-12-22 02:06:40 +03:00
|
|
|
}
|
|
|
|
|
2019-11-10 15:05:01 +03:00
|
|
|
bt.selectCursor = maxInt(bt.selectCursor-1, 0)
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
return nil
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-07-31 17:43:43 +03:00
|
|
|
func (bt *bugTable) cursorClamp(v *gocui.View) error {
|
2019-11-10 15:05:01 +03:00
|
|
|
y := bt.selectCursor
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
y = minInt(y, bt.getTableLength()-1)
|
|
|
|
y = maxInt(y, 0)
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.selectCursor = y
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) nextPage(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
_, max := v.Size()
|
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
if bt.pageCursor+max >= len(bt.allIds) {
|
2018-07-31 17:43:43 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.pageCursor += max
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
return bt.doPaginate(max)
|
2018-07-31 17:43:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) previousPage(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
_, max := v.Size()
|
|
|
|
|
2018-12-22 02:43:59 +03:00
|
|
|
if bt.pageCursor == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-23 23:16:27 +03:00
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.pageCursor = maxInt(0, bt.pageCursor-max)
|
2018-07-31 17:43:43 +03:00
|
|
|
|
2018-09-02 16:46:43 +03:00
|
|
|
return bt.doPaginate(max)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
func (bt *bugTable) newBug(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return newBugWithEditor(bt.repo)
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
func (bt *bugTable) openBug(g *gocui.Gui, v *gocui.View) error {
|
termui: fix a crash when trying to open a bug when there are none
Nothing prevented you from pressing Enter in bug listing even when there
were no open bugs. Doing so resulted in:
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/MichaelMure/git-bug/termui.(*bugTable).openBug(0xc00007aa80, 0xc000354000, 0xc00036c120, 0x2, 0x2)
/build/source/termui/bug_table.go:440 +0x17f
github.com/awesome-gocui/gocui.(*Gui).execKeybinding(0xc000354000, 0xc00036c120, 0xc0003102a0, 0xc00007a001, 0xc000225b2c, 0xc000000180)
/build/go/pkg/mod/github.com/awesome-gocui/gocui@v0.6.1-0.20191115151952-a34ffb055986/gui.go:808 +0x65
github.com/awesome-gocui/gocui.(*Gui).execKeybindings(0xc000354000, 0xc00036c120, 0xc000225b38, 0x3, 0x4, 0x3)
/build/go/pkg/mod/github.com/awesome-gocui/gocui@v0.6.1-0.20191115151952-a34ffb055986/gui.go:787 +0xed
github.com/awesome-gocui/gocui.(*Gui).onKey(0xc000354000, 0xc000225b38, 0x2, 0x0)
/build/go/pkg/mod/github.com/awesome-gocui/gocui@v0.6.1-0.20191115151952-a34ffb055986/gui.go:745 +0x164
github.com/awesome-gocui/gocui.(*Gui).handleEvent(...)
/build/go/pkg/mod/github.com/awesome-gocui/gocui@v0.6.1-0.20191115151952-a34ffb055986/gui.go:506
github.com/awesome-gocui/gocui.(*Gui).MainLoop(0xc000354000, 0x0, 0x0)
/build/go/pkg/mod/github.com/awesome-gocui/gocui@v0.6.1-0.20191115151952-a34ffb055986/gui.go:466 +0x202
github.com/MichaelMure/git-bug/termui.initGui(0x0)
/build/source/termui/termui.go:113 +0x12c
github.com/MichaelMure/git-bug/termui.Run(0xc000228000, 0xc000078b30, 0x0)
/build/source/termui/termui.go:66 +0x185
github.com/MichaelMure/git-bug/commands.runTermUI(0x1211bc0, 0x12478e0, 0x0, 0x0, 0x0, 0x0)
/build/source/commands/termui.go:18 +0xd5
github.com/spf13/cobra.(*Command).execute(0x1211bc0, 0x12478e0, 0x0, 0x0, 0x1211bc0, 0x12478e0)
/build/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:840 +0x453
github.com/spf13/cobra.(*Command).ExecuteC(0x1210960, 0x0, 0x0, 0x0)
/build/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:945 +0x317
github.com/spf13/cobra.(*Command).Execute(...)
/build/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:885
github.com/MichaelMure/git-bug/commands.Execute()
/build/source/commands/root.go:54 +0x2d
main.main()
/build/source/git-bug.go:14 +0x20
2020-04-16 19:59:42 +03:00
|
|
|
if len(bt.excerpts) == 0 {
|
|
|
|
// There are no open bugs, just do nothing
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-10 15:05:01 +03:00
|
|
|
id := bt.excerpts[bt.selectCursor].Id
|
2019-04-21 01:55:39 +03:00
|
|
|
b, err := bt.repo.ResolveBug(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ui.showBug.SetBug(b)
|
2018-08-01 03:15:40 +03:00
|
|
|
return ui.activateWindow(ui.showBug)
|
|
|
|
}
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
func (bt *bugTable) pull(g *gocui.Gui, v *gocui.View) error {
|
2018-09-11 20:28:32 +03:00
|
|
|
ui.msgPopup.Activate("Pull from remote "+defaultRemote, "...")
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
go func() {
|
2018-09-11 20:28:32 +03:00
|
|
|
stdout, err := bt.repo.Fetch(defaultRemote)
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.UpdateMessage(stdout)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
beginLine := ""
|
|
|
|
|
2019-03-27 23:44:11 +03:00
|
|
|
for result := range bt.repo.MergeAll(defaultRemote) {
|
|
|
|
if result.Status == entity.MergeStatusNothing {
|
2018-08-12 22:09:30 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-03-27 23:44:11 +03:00
|
|
|
if result.Err != nil {
|
2018-08-12 22:09:30 +03:00
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
} else {
|
2018-12-01 19:09:13 +03:00
|
|
|
_, _ = fmt.Fprintf(&buffer, "%s%s: %s",
|
2019-08-12 17:12:14 +03:00
|
|
|
beginLine, colors.Cyan(result.Entity.Id().Human()), result,
|
2018-08-12 22:09:30 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
beginLine = "\n"
|
|
|
|
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.UpdateMessage(buffer.String())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 19:09:13 +03:00
|
|
|
_, _ = fmt.Fprintf(&buffer, "%sdone", beginLine)
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.UpdateMessage(buffer.String())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) push(g *gocui.Gui, v *gocui.View) error {
|
2018-09-11 20:28:32 +03:00
|
|
|
ui.msgPopup.Activate("Push to remote "+defaultRemote, "...")
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// TODO: make the remote configurable
|
2018-09-11 20:28:32 +03:00
|
|
|
stdout, err := bt.repo.Push(defaultRemote)
|
2018-08-12 22:09:30 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.UpdateMessage(stdout)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-09-11 20:28:32 +03:00
|
|
|
|
|
|
|
func (bt *bugTable) changeQuery(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return editQueryWithEditor(bt)
|
|
|
|
}
|