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"
|
2018-08-12 22:09:30 +03:00
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2018-07-30 19:09:44 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util"
|
2018-08-02 17:48:07 +03:00
|
|
|
"github.com/dustin/go-humanize"
|
2018-07-30 18:00:10 +03:00
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
)
|
|
|
|
|
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-08-12 22:09:30 +03:00
|
|
|
const remote = "origin"
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
type bugTable struct {
|
2018-08-23 22:24:57 +03:00
|
|
|
repo *cache.RepoCache
|
2018-08-01 03:15:40 +03:00
|
|
|
allIds []string
|
2018-08-23 22:24:57 +03:00
|
|
|
bugs []*cache.BugCache
|
2018-08-01 03:15:40 +03:00
|
|
|
pageCursor int
|
|
|
|
selectCursor int
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-08-23 22:24:57 +03:00
|
|
|
func newBugTable(cache *cache.RepoCache) *bugTable {
|
2018-07-30 18:00:10 +03:00
|
|
|
return &bugTable{
|
2018-08-02 17:35:13 +03:00
|
|
|
repo: cache,
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
v, err := g.SetView(bugTableHeaderView, -1, -1, maxX, 3)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
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
|
|
|
|
2018-07-31 23:30:50 +03:00
|
|
|
v, err = g.SetView(bugTableView, -1, 1, maxX, maxY-3)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
|
|
|
v.Highlight = true
|
|
|
|
v.SelBgColor = gocui.ColorWhite
|
|
|
|
v.SelFgColor = gocui.ColorBlack
|
2018-08-01 03:15:40 +03:00
|
|
|
|
|
|
|
// restore the cursor
|
|
|
|
// window is too small to set the cursor properly, ignoring the error
|
|
|
|
_ = v.SetCursor(0, bt.selectCursor)
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
2018-07-31 17:43:43 +03:00
|
|
|
_, 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()
|
2018-07-31 17:43:43 +03:00
|
|
|
bt.render(v, maxX)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
v, err = g.SetView(bugTableFooterView, -1, maxY-4, maxX, maxY)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
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
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
v, err = g.SetView(bugTableInstructionView, -1, maxY-2, maxX, maxY)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Frame = false
|
|
|
|
v.BgColor = gocui.ColorBlue
|
|
|
|
|
2018-08-12 22:09:30 +03:00
|
|
|
fmt.Fprintf(v, "[q] Quit [←↓↑→,hjkl] Navigation [enter] Open bug [n] New bug [i] Pull [o] Push")
|
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
|
|
|
|
if err := g.SetKeybinding(bugTableView, 'q', gocui.ModNone, quit); err != nil {
|
|
|
|
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-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) disable(g *gocui.Gui) error {
|
2018-08-17 13:37:58 +03:00
|
|
|
if err := g.DeleteView(bugTableView); err != nil && err != gocui.ErrUnknownView {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2018-08-17 13:37:58 +03:00
|
|
|
if err := g.DeleteView(bugTableHeaderView); err != nil && err != gocui.ErrUnknownView {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2018-08-17 13:37:58 +03:00
|
|
|
if err := g.DeleteView(bugTableFooterView); err != nil && err != gocui.ErrUnknownView {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
2018-08-17 13:37:58 +03:00
|
|
|
if err := g.DeleteView(bugTableInstructionView); err != nil && err != gocui.ErrUnknownView {
|
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 {
|
2018-09-02 17:36:48 +03:00
|
|
|
bt.allIds = bt.repo.AllBugsId(cache.OrderByCreation, cache.OrderAscending)
|
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 {
|
2018-08-23 22:24:57 +03:00
|
|
|
bt.bugs = []*cache.BugCache{}
|
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
|
|
|
|
2018-08-23 22:24:57 +03:00
|
|
|
bt.bugs = make([]*cache.BugCache, len(ids))
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
for i, id := range ids {
|
2018-08-02 17:35:13 +03:00
|
|
|
b, err := bt.repo.ResolveBug(id)
|
2018-07-31 17:43:43 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
bt.bugs[i] = b
|
2018-07-30 18:00:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) getTableLength() int {
|
|
|
|
return len(bt.bugs)
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:09:44 +03:00
|
|
|
func (bt *bugTable) getColumnWidths(maxX int) map[string]int {
|
|
|
|
m := make(map[string]int)
|
|
|
|
m["id"] = 10
|
|
|
|
m["status"] = 8
|
|
|
|
|
2018-08-02 17:48:07 +03:00
|
|
|
left := maxX - 5 - m["id"] - m["status"]
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2018-08-02 17:48:07 +03:00
|
|
|
m["summary"] = maxInt(11, left/6)
|
2018-07-30 19:09:44 +03:00
|
|
|
left -= m["summary"]
|
|
|
|
|
2018-08-02 17:48:07 +03:00
|
|
|
m["lastEdit"] = maxInt(19, left/6)
|
|
|
|
left -= m["lastEdit"]
|
|
|
|
|
2018-07-30 19:09:44 +03:00
|
|
|
m["author"] = maxInt(left*2/5, 15)
|
|
|
|
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)
|
|
|
|
|
2018-07-30 18:00:10 +03:00
|
|
|
for _, b := range bt.bugs {
|
2018-07-30 19:09:44 +03:00
|
|
|
person := bug.Person{}
|
2018-08-02 17:35:13 +03:00
|
|
|
snap := b.Snapshot()
|
|
|
|
if len(snap.Comments) > 0 {
|
|
|
|
create := snap.Comments[0]
|
2018-07-30 19:09:44 +03:00
|
|
|
person = create.Author
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
id := util.LeftPaddedString(snap.HumanId(), columnWidths["id"], 2)
|
|
|
|
status := util.LeftPaddedString(snap.Status.String(), columnWidths["status"], 2)
|
|
|
|
title := util.LeftPaddedString(snap.Title, columnWidths["title"], 2)
|
2018-07-30 19:09:44 +03:00
|
|
|
author := util.LeftPaddedString(person.Name, columnWidths["author"], 2)
|
2018-08-02 17:35:13 +03:00
|
|
|
summary := util.LeftPaddedString(snap.Summary(), columnWidths["summary"], 2)
|
2018-08-23 20:19:16 +03:00
|
|
|
lastEdit := util.LeftPaddedString(humanize.Time(snap.LastEditTime()), columnWidths["lastEdit"], 2)
|
2018-07-30 19:09:44 +03:00
|
|
|
|
2018-08-08 23:21:02 +03:00
|
|
|
fmt.Fprintf(v, "%s %s %s %s %s %s\n",
|
|
|
|
util.Cyan(id),
|
|
|
|
util.Yellow(status),
|
|
|
|
title,
|
|
|
|
util.Magenta(author),
|
|
|
|
summary,
|
|
|
|
lastEdit,
|
|
|
|
)
|
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)
|
|
|
|
|
|
|
|
id := util.LeftPaddedString("ID", columnWidths["id"], 2)
|
|
|
|
status := util.LeftPaddedString("STATUS", columnWidths["status"], 2)
|
|
|
|
title := util.LeftPaddedString("TITLE", columnWidths["title"], 2)
|
|
|
|
author := util.LeftPaddedString("AUTHOR", columnWidths["author"], 2)
|
|
|
|
summary := util.LeftPaddedString("SUMMARY", columnWidths["summary"], 2)
|
2018-08-02 17:48:07 +03:00
|
|
|
lastEdit := util.LeftPaddedString("LAST EDIT", columnWidths["lastEdit"], 2)
|
2018-07-30 19:09:44 +03:00
|
|
|
|
|
|
|
fmt.Fprintf(v, "\n")
|
2018-08-02 17:48:07 +03:00
|
|
|
fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, summary, lastEdit)
|
2018-07-30 18:00:10 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) renderFooter(v *gocui.View, maxX int) {
|
2018-07-31 23:30:50 +03:00
|
|
|
fmt.Fprintf(v, " \nShowing %d of %d bugs", len(bt.bugs), len(bt.allIds))
|
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 {
|
|
|
|
_, y := v.Cursor()
|
|
|
|
y = minInt(y+1, bt.getTableLength()-1)
|
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
// window is too small to set the cursor properly, ignoring the error
|
|
|
|
_ = v.SetCursor(0, y)
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.selectCursor = y
|
2018-07-31 17:43:43 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
_, y := v.Cursor()
|
|
|
|
y = maxInt(y-1, 0)
|
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
// window is too small to set the cursor properly, ignoring the error
|
|
|
|
_ = v.SetCursor(0, y)
|
2018-08-01 03:15:40 +03:00
|
|
|
bt.selectCursor = y
|
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 {
|
|
|
|
_, y := v.Cursor()
|
|
|
|
|
|
|
|
y = minInt(y, bt.getTableLength()-1)
|
|
|
|
y = maxInt(y, 0)
|
|
|
|
|
2018-07-31 23:19:11 +03:00
|
|
|
// window is too small to set the cursor properly, ignoring the error
|
|
|
|
_ = v.SetCursor(0, y)
|
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-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 {
|
|
|
|
_, y := v.Cursor()
|
2018-08-17 13:10:28 +03:00
|
|
|
ui.showBug.SetBug(bt.bugs[y])
|
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 {
|
|
|
|
// Note: this is very hacky
|
|
|
|
|
|
|
|
ui.msgPopup.Activate("Pull from remote "+remote, "...")
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
stdout, err := bt.repo.Fetch(remote)
|
|
|
|
|
|
|
|
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 := ""
|
|
|
|
|
|
|
|
for merge := range bt.repo.MergeAll(remote) {
|
|
|
|
if merge.Status == bug.MsgMergeNothing {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if merge.Err != nil {
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(&buffer, "%s%s: %s",
|
2018-09-08 15:17:08 +03:00
|
|
|
beginLine, util.Cyan(merge.Bug.HumanId()), merge.Status,
|
2018-08-12 22:09:30 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
beginLine = "\n"
|
|
|
|
|
|
|
|
g.Update(func(gui *gocui.Gui) error {
|
|
|
|
ui.msgPopup.UpdateMessage(buffer.String())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(&buffer, "%sdone", beginLine)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
ui.msgPopup.Activate("Push to remote "+remote, "...")
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
// TODO: make the remote configurable
|
|
|
|
stdout, err := bt.repo.Push(remote)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|