2018-08-01 03:15:40 +03:00
|
|
|
package termui
|
|
|
|
|
|
|
|
import (
|
2018-08-09 16:28:32 +03:00
|
|
|
"bytes"
|
2022-02-15 23:52:36 +03:00
|
|
|
"errors"
|
2018-08-01 03:15:40 +03:00
|
|
|
"fmt"
|
2018-08-09 16:28:32 +03:00
|
|
|
"strings"
|
2018-08-08 23:22:35 +03:00
|
|
|
|
2022-02-15 23:52:36 +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
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2022-08-19 00:34:05 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entities/bug"
|
2019-08-12 17:12:14 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2018-09-11 23:04:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/colors"
|
2018-08-01 03:15:40 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const showBugView = "showBugView"
|
|
|
|
const showBugSidebarView = "showBugSidebarView"
|
|
|
|
const showBugInstructionView = "showBugInstructionView"
|
2018-08-09 02:35:31 +03:00
|
|
|
const showBugHeaderView = "showBugHeaderView"
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-09 03:46:26 +03:00
|
|
|
const timeLayout = "Jan 2 2006"
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2020-04-12 12:11:01 +03:00
|
|
|
var showBugHelp = helpBar{
|
|
|
|
{"q", "Save and return"},
|
|
|
|
{"←↓↑→,hjkl", "Navigation"},
|
|
|
|
{"o", "Toggle open/close"},
|
|
|
|
{"e", "Edit"},
|
|
|
|
{"c", "Comment"},
|
|
|
|
{"t", "Change title"},
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
type showBug struct {
|
2018-08-23 22:24:57 +03:00
|
|
|
cache *cache.RepoCache
|
|
|
|
bug *cache.BugCache
|
2018-08-12 00:36:03 +03:00
|
|
|
childViews []string
|
|
|
|
mainSelectableView []string
|
|
|
|
sideSelectableView []string
|
|
|
|
selected string
|
|
|
|
isOnSide bool
|
|
|
|
scroll int
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
|
2018-08-23 22:24:57 +03:00
|
|
|
func newShowBug(cache *cache.RepoCache) *showBug {
|
2018-08-01 03:15:40 +03:00
|
|
|
return &showBug{
|
|
|
|
cache: cache,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 22:24:57 +03:00
|
|
|
func (sb *showBug) SetBug(bug *cache.BugCache) {
|
2018-08-09 15:51:19 +03:00
|
|
|
sb.bug = bug
|
|
|
|
sb.scroll = 0
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.selected = ""
|
|
|
|
sb.isOnSide = false
|
2018-08-09 15:51:19 +03:00
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
func (sb *showBug) layout(g *gocui.Gui) error {
|
|
|
|
maxX, maxY := g.Size()
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.childViews = nil
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err := g.SetView(showBugView, 0, 0, maxX*2/3, maxY-2, 0)
|
2018-08-01 03:15:40 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2022-02-15 23:52:36 +03:00
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
sb.childViews = append(sb.childViews, showBugView)
|
2018-08-01 03:15:40 +03:00
|
|
|
v.Frame = false
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2018-08-03 18:29:53 +03:00
|
|
|
err = sb.renderMain(g, v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err = g.SetView(showBugSidebarView, maxX*2/3+1, 0, maxX-1, maxY-2, 0)
|
2018-08-01 03:15:40 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2022-02-15 23:52:36 +03:00
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
sb.childViews = append(sb.childViews, showBugSidebarView)
|
2018-08-12 00:36:03 +03:00
|
|
|
v.Frame = false
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2018-08-12 00:36:03 +03:00
|
|
|
err = sb.renderSidebar(g, v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err = g.SetView(showBugInstructionView, -1, maxY-2, maxX, maxY, 0)
|
2018-08-01 03:15:40 +03:00
|
|
|
|
|
|
|
if err != nil {
|
2022-02-15 23:52:36 +03:00
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
sb.childViews = append(sb.childViews, showBugInstructionView)
|
2018-08-01 03:15:40 +03:00
|
|
|
v.Frame = false
|
2020-07-13 14:27:09 +03:00
|
|
|
v.FgColor = gocui.ColorWhite
|
2018-08-12 03:42:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
v.Clear()
|
2020-08-22 16:27:57 +03:00
|
|
|
_, _ = fmt.Fprint(v, showBugHelp.Render(maxX))
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-09 17:48:23 +03:00
|
|
|
_, err = g.SetViewOnTop(showBugInstructionView)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
_, err = g.SetCurrentView(showBugView)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) keybindings(g *gocui.Gui) error {
|
|
|
|
// Return
|
2018-09-19 20:30:04 +03:00
|
|
|
if err := g.SetKeybinding(showBugView, 'q', gocui.ModNone, sb.saveAndBack); err != nil {
|
2018-08-01 03:15:40 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
// Scrolling
|
2018-08-01 03:15:40 +03:00
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyPgup, gocui.ModNone,
|
|
|
|
sb.scrollUp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyPgdn, gocui.ModNone,
|
|
|
|
sb.scrollDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-08 23:22:35 +03:00
|
|
|
// Down
|
|
|
|
if err := g.SetKeybinding(showBugView, 'j', gocui.ModNone,
|
|
|
|
sb.selectNext); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyArrowDown, gocui.ModNone,
|
|
|
|
sb.selectNext); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Up
|
|
|
|
if err := g.SetKeybinding(showBugView, 'k', gocui.ModNone,
|
|
|
|
sb.selectPrevious); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyArrowUp, gocui.ModNone,
|
|
|
|
sb.selectPrevious); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
// Left
|
|
|
|
if err := g.SetKeybinding(showBugView, 'h', gocui.ModNone,
|
|
|
|
sb.left); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyArrowLeft, gocui.ModNone,
|
|
|
|
sb.left); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Right
|
|
|
|
if err := g.SetKeybinding(showBugView, 'l', gocui.ModNone,
|
|
|
|
sb.right); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding(showBugView, gocui.KeyArrowRight, gocui.ModNone,
|
|
|
|
sb.right); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
// Comment
|
|
|
|
if err := g.SetKeybinding(showBugView, 'c', gocui.ModNone,
|
|
|
|
sb.comment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-10-02 23:14:06 +03:00
|
|
|
// Open/close
|
|
|
|
if err := g.SetKeybinding(showBugView, 'o', gocui.ModNone,
|
|
|
|
sb.toggleOpenClose); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
// Title
|
|
|
|
if err := g.SetKeybinding(showBugView, 't', gocui.ModNone,
|
2018-08-09 02:35:31 +03:00
|
|
|
sb.setTitle); err != nil {
|
2018-08-02 17:35:13 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-10-04 19:31:46 +03:00
|
|
|
// Edit
|
|
|
|
if err := g.SetKeybinding(showBugView, 'e', gocui.ModNone,
|
|
|
|
sb.edit); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) disable(g *gocui.Gui) error {
|
2018-08-03 18:29:53 +03:00
|
|
|
for _, view := range sb.childViews {
|
2022-02-15 23:52:36 +03:00
|
|
|
if err := g.DeleteView(view); err != nil && !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-03 18:29:53 +03:00
|
|
|
return err
|
|
|
|
}
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
|
|
|
|
maxX, _ := mainView.Size()
|
|
|
|
x0, y0, _, _, _ := g.ViewPosition(mainView.Name())
|
2018-08-09 02:35:31 +03:00
|
|
|
|
|
|
|
y0 -= sb.scroll
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
snap := sb.bug.Snapshot()
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.mainSelectableView = nil
|
2018-08-09 02:35:31 +03:00
|
|
|
|
2018-09-30 12:01:04 +03:00
|
|
|
createTimelineItem := snap.Timeline[0].(*bug.CreateTimelineItem)
|
|
|
|
|
|
|
|
edited := ""
|
|
|
|
if createTimelineItem.Edited() {
|
|
|
|
edited = " (edited)"
|
|
|
|
}
|
|
|
|
|
|
|
|
bugHeader := fmt.Sprintf("[%s] %s\n\n[%s] %s opened this bug on %s%s",
|
2019-08-12 17:12:14 +03:00
|
|
|
colors.Cyan(snap.Id().Human()),
|
2018-09-11 23:04:16 +03:00
|
|
|
colors.Bold(snap.Title),
|
|
|
|
colors.Yellow(snap.Status),
|
2018-10-07 19:27:23 +03:00
|
|
|
colors.Magenta(snap.Author.DisplayName()),
|
2020-06-26 00:18:17 +03:00
|
|
|
snap.CreateTime.Format(timeLayout),
|
2018-09-30 12:01:04 +03:00
|
|
|
edited,
|
2018-08-09 15:36:23 +03:00
|
|
|
)
|
2020-06-23 19:02:54 +03:00
|
|
|
bugHeader, lines := text.Wrap(bugHeader, maxX, text.WrapIndent(" "))
|
2018-08-09 15:36:23 +03:00
|
|
|
|
|
|
|
v, err := sb.createOpView(g, showBugHeaderView, x0, y0, maxX+1, lines, false)
|
2018-08-03 18:29:53 +03:00
|
|
|
if err != nil {
|
2018-08-09 15:36:23 +03:00
|
|
|
return err
|
2018-08-03 18:29:53 +03:00
|
|
|
}
|
|
|
|
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, bugHeader)
|
2018-08-09 15:36:23 +03:00
|
|
|
y0 += lines + 1
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2018-10-04 19:30:56 +03:00
|
|
|
for _, op := range snap.Timeline {
|
2019-08-12 17:12:14 +03:00
|
|
|
viewName := op.Id().String()
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-09 03:46:26 +03:00
|
|
|
// TODO: me might skip the rendering of blocks that are outside of the view
|
2018-08-12 00:36:03 +03:00
|
|
|
// but to do that we need to rework how sb.mainSelectableView is maintained
|
2018-08-09 03:46:26 +03:00
|
|
|
|
2020-02-08 18:17:15 +03:00
|
|
|
switch op := op.(type) {
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-09-30 12:01:04 +03:00
|
|
|
case *bug.CreateTimelineItem:
|
2018-12-23 23:46:47 +03:00
|
|
|
var content string
|
|
|
|
var lines int
|
|
|
|
|
2020-02-08 18:17:15 +03:00
|
|
|
if op.MessageIsEmpty() {
|
2018-12-23 23:46:47 +03:00
|
|
|
content, lines = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4)
|
|
|
|
} else {
|
2020-02-08 18:17:15 +03:00
|
|
|
content, lines = text.WrapLeftPadded(op.Message, maxX-1, 4)
|
2018-12-23 23:46:47 +03:00
|
|
|
}
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2018-08-08 23:22:35 +03:00
|
|
|
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
|
2018-08-03 18:29:53 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-03 18:29:53 +03:00
|
|
|
y0 += lines + 2
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
case *bug.AddCommentTimelineItem:
|
2018-09-30 12:01:04 +03:00
|
|
|
edited := ""
|
2020-02-08 18:17:15 +03:00
|
|
|
if op.Edited() {
|
2018-09-30 12:01:04 +03:00
|
|
|
edited = " (edited)"
|
|
|
|
}
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2018-12-23 23:46:47 +03:00
|
|
|
var message string
|
2020-02-08 18:17:15 +03:00
|
|
|
if op.MessageIsEmpty() {
|
2018-12-23 23:46:47 +03:00
|
|
|
message, _ = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4)
|
|
|
|
} else {
|
2020-02-08 18:17:15 +03:00
|
|
|
message, _ = text.WrapLeftPadded(op.Message, maxX-1, 4)
|
2018-12-23 23:46:47 +03:00
|
|
|
}
|
|
|
|
|
2018-09-30 12:01:04 +03:00
|
|
|
content := fmt.Sprintf("%s commented on %s%s\n\n%s",
|
2020-02-08 18:17:15 +03:00
|
|
|
colors.Magenta(op.Author.DisplayName()),
|
|
|
|
op.CreatedAt.Time().Format(timeLayout),
|
2018-09-30 12:01:04 +03:00
|
|
|
edited,
|
2018-08-09 15:51:19 +03:00
|
|
|
message,
|
2018-08-09 15:36:23 +03:00
|
|
|
)
|
2018-09-11 23:04:16 +03:00
|
|
|
content, lines = text.Wrap(content, maxX)
|
2018-08-09 15:36:23 +03:00
|
|
|
|
|
|
|
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-09 15:36:23 +03:00
|
|
|
y0 += lines + 2
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
case *bug.SetTitleTimelineItem:
|
2018-08-09 15:36:23 +03:00
|
|
|
content := fmt.Sprintf("%s changed the title to %s on %s",
|
2020-02-08 18:17:15 +03:00
|
|
|
colors.Magenta(op.Author.DisplayName()),
|
|
|
|
colors.Bold(op.Title),
|
|
|
|
op.UnixTime.Time().Format(timeLayout),
|
2018-08-09 15:36:23 +03:00
|
|
|
)
|
2018-09-11 23:04:16 +03:00
|
|
|
content, lines := text.Wrap(content, maxX)
|
2018-08-09 15:36:23 +03:00
|
|
|
|
2018-08-09 16:28:32 +03:00
|
|
|
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-09 16:28:32 +03:00
|
|
|
y0 += lines + 2
|
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
case *bug.SetStatusTimelineItem:
|
2018-08-09 16:28:32 +03:00
|
|
|
content := fmt.Sprintf("%s %s the bug on %s",
|
2020-02-08 18:17:15 +03:00
|
|
|
colors.Magenta(op.Author.DisplayName()),
|
|
|
|
colors.Bold(op.Status.Action()),
|
|
|
|
op.UnixTime.Time().Format(timeLayout),
|
2018-08-09 16:28:32 +03:00
|
|
|
)
|
2018-09-11 23:04:16 +03:00
|
|
|
content, lines := text.Wrap(content, maxX)
|
2018-08-09 16:28:32 +03:00
|
|
|
|
|
|
|
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-09 16:28:32 +03:00
|
|
|
y0 += lines + 2
|
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
case *bug.LabelChangeTimelineItem:
|
2018-08-09 16:28:32 +03:00
|
|
|
var added []string
|
2020-02-08 18:17:15 +03:00
|
|
|
for _, label := range op.Added {
|
2018-09-11 23:04:16 +03:00
|
|
|
added = append(added, colors.Bold("\""+label+"\""))
|
2018-08-09 16:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var removed []string
|
2020-02-08 18:17:15 +03:00
|
|
|
for _, label := range op.Removed {
|
2018-09-11 23:04:16 +03:00
|
|
|
removed = append(removed, colors.Bold("\""+label+"\""))
|
2018-08-09 16:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var action bytes.Buffer
|
|
|
|
|
|
|
|
if len(added) > 0 {
|
|
|
|
action.WriteString("added ")
|
2018-08-11 23:27:45 +03:00
|
|
|
action.WriteString(strings.Join(added, ", "))
|
2018-08-09 16:28:32 +03:00
|
|
|
|
|
|
|
if len(removed) > 0 {
|
|
|
|
action.WriteString(" and ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(removed) > 0 {
|
|
|
|
action.WriteString("removed ")
|
2018-08-11 23:27:45 +03:00
|
|
|
action.WriteString(strings.Join(removed, ", "))
|
2018-08-09 16:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(added)+len(removed) > 1 {
|
|
|
|
action.WriteString(" labels")
|
|
|
|
} else {
|
|
|
|
action.WriteString(" label")
|
|
|
|
}
|
|
|
|
|
|
|
|
content := fmt.Sprintf("%s %s on %s",
|
2020-02-08 18:17:15 +03:00
|
|
|
colors.Magenta(op.Author.DisplayName()),
|
2018-08-09 16:28:32 +03:00
|
|
|
action.String(),
|
2020-02-08 18:17:15 +03:00
|
|
|
op.UnixTime.Time().Format(timeLayout),
|
2018-08-09 16:28:32 +03:00
|
|
|
)
|
2018-09-11 23:04:16 +03:00
|
|
|
content, lines := text.Wrap(content, maxX)
|
2018-08-09 16:28:32 +03:00
|
|
|
|
2018-08-09 15:36:23 +03:00
|
|
|
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
|
2018-08-03 18:29:53 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-09 15:36:23 +03:00
|
|
|
y0 += lines + 2
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-23 23:46:47 +03:00
|
|
|
// emptyMessagePlaceholder return a formatted placeholder for an empty message
|
|
|
|
func emptyMessagePlaceholder() string {
|
2020-09-21 13:11:39 +03:00
|
|
|
return colors.BlackBold(colors.WhiteBg("No description provided."))
|
2018-12-23 23:46:47 +03:00
|
|
|
}
|
|
|
|
|
2018-08-08 23:22:35 +03:00
|
|
|
func (sb *showBug) createOpView(g *gocui.Gui, name string, x0 int, y0 int, maxX int, height int, selectable bool) (*gocui.View, error) {
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err := g.SetView(name, x0, y0, maxX, y0+height+1, 0)
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2022-02-15 23:52:36 +03:00
|
|
|
if err != nil && !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-09 02:35:31 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-03 18:29:53 +03:00
|
|
|
|
2018-08-09 02:35:31 +03:00
|
|
|
sb.childViews = append(sb.childViews, name)
|
2018-08-08 23:22:35 +03:00
|
|
|
|
2018-08-09 02:35:31 +03:00
|
|
|
if selectable {
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.mainSelectableView = append(sb.mainSelectableView, name)
|
2018-08-03 18:29:53 +03:00
|
|
|
}
|
|
|
|
|
2018-08-08 23:22:35 +03:00
|
|
|
v.Frame = sb.selected == name
|
|
|
|
|
2018-08-03 18:29:53 +03:00
|
|
|
v.Clear()
|
|
|
|
|
|
|
|
return v, nil
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
func (sb *showBug) createSideView(g *gocui.Gui, name string, x0 int, y0 int, maxX int, height int) (*gocui.View, error) {
|
2019-11-03 22:47:29 +03:00
|
|
|
v, err := g.SetView(name, x0, y0, maxX, y0+height+1, 0)
|
2018-08-12 00:36:03 +03:00
|
|
|
|
2022-02-15 23:52:36 +03:00
|
|
|
if err != nil && !errors.Is(err, gocui.ErrUnknownView) {
|
2018-08-12 00:36:03 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.childViews = append(sb.childViews, name)
|
|
|
|
sb.sideSelectableView = append(sb.sideSelectableView, name)
|
|
|
|
|
|
|
|
v.Frame = sb.selected == name
|
|
|
|
|
|
|
|
v.Clear()
|
|
|
|
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
|
|
|
|
maxX, _ := sideView.Size()
|
|
|
|
x0, y0, _, _, _ := g.ViewPosition(sideView.Name())
|
|
|
|
maxX += x0
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
snap := sb.bug.Snapshot()
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.sideSelectableView = nil
|
|
|
|
|
|
|
|
labelStr := make([]string, len(snap.Labels))
|
|
|
|
for i, l := range snap.Labels {
|
2019-08-28 22:13:45 +03:00
|
|
|
lc := l.Color()
|
|
|
|
lc256 := lc.Term256()
|
|
|
|
labelStr[i] = lc256.Escape() + "◼ " + lc256.Unescape() + l.String()
|
2018-08-12 00:36:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
labels := strings.Join(labelStr, "\n")
|
2018-09-11 23:04:16 +03:00
|
|
|
labels, lines := text.WrapLeftPadded(labels, maxX, 2)
|
2018-08-12 00:36:03 +03:00
|
|
|
|
2019-08-28 21:32:35 +03:00
|
|
|
content := fmt.Sprintf("%s\n\n%s", colors.Bold(" Labels"), labels)
|
2018-08-01 03:15:40 +03:00
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
v, err := sb.createSideView(g, "sideLabels", x0, y0, maxX, lines+2)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
2018-08-12 00:36:03 +03:00
|
|
|
|
2018-12-23 23:46:47 +03:00
|
|
|
_, _ = fmt.Fprint(v, content)
|
2018-08-12 00:36:03 +03:00
|
|
|
|
|
|
|
return nil
|
2018-08-01 03:15:40 +03:00
|
|
|
}
|
|
|
|
|
2018-08-09 15:45:02 +03:00
|
|
|
func (sb *showBug) saveAndBack(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
err := sb.bug.CommitAsNeeded()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-13 13:43:47 +03:00
|
|
|
err = ui.activateWindow(ui.bugTable)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) scrollUp(g *gocui.Gui, v *gocui.View) error {
|
2018-08-09 03:46:26 +03:00
|
|
|
mainView, err := g.View(showBugView)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, maxY := mainView.Size()
|
|
|
|
|
|
|
|
sb.scroll -= maxY / 2
|
|
|
|
|
|
|
|
sb.scroll = maxInt(sb.scroll, 0)
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) scrollDown(g *gocui.Gui, v *gocui.View) error {
|
2018-08-09 03:46:26 +03:00
|
|
|
_, maxY := v.Size()
|
|
|
|
|
2018-08-12 03:45:35 +03:00
|
|
|
lastViewName := sb.mainSelectableView[len(sb.mainSelectableView)-1]
|
2018-08-09 03:46:26 +03:00
|
|
|
|
|
|
|
lastView, err := g.View(lastViewName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, vMaxY := lastView.Size()
|
|
|
|
|
|
|
|
_, vy0, _, _, err := g.ViewPosition(lastViewName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
maxScroll := vy0 + sb.scroll + vMaxY - maxY
|
|
|
|
|
|
|
|
sb.scroll += maxY / 2
|
|
|
|
|
|
|
|
sb.scroll = minInt(sb.scroll, maxScroll)
|
|
|
|
|
2018-08-01 03:15:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-02 17:35:13 +03:00
|
|
|
|
2018-08-08 23:22:35 +03:00
|
|
|
func (sb *showBug) selectPrevious(g *gocui.Gui, v *gocui.View) error {
|
2018-08-12 00:36:03 +03:00
|
|
|
var selectable []string
|
|
|
|
if sb.isOnSide {
|
|
|
|
selectable = sb.sideSelectableView
|
|
|
|
} else {
|
|
|
|
selectable = sb.mainSelectableView
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, name := range selectable {
|
2018-08-08 23:22:35 +03:00
|
|
|
if name == sb.selected {
|
2018-08-09 02:35:31 +03:00
|
|
|
// special case to scroll up to the top
|
|
|
|
if i == 0 {
|
|
|
|
sb.scroll = 0
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.selected = selectable[maxInt(i-1, 0)]
|
2018-09-13 13:43:47 +03:00
|
|
|
return sb.focusView(g)
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
if sb.selected == "" && len(selectable) > 0 {
|
|
|
|
sb.selected = selectable[0]
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
|
2018-09-13 13:43:47 +03:00
|
|
|
return sb.focusView(g)
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) selectNext(g *gocui.Gui, v *gocui.View) error {
|
2018-08-12 00:36:03 +03:00
|
|
|
var selectable []string
|
|
|
|
if sb.isOnSide {
|
|
|
|
selectable = sb.sideSelectableView
|
|
|
|
} else {
|
|
|
|
selectable = sb.mainSelectableView
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, name := range selectable {
|
2018-08-08 23:22:35 +03:00
|
|
|
if name == sb.selected {
|
2018-08-12 00:36:03 +03:00
|
|
|
sb.selected = selectable[minInt(i+1, len(selectable)-1)]
|
2018-09-13 13:43:47 +03:00
|
|
|
return sb.focusView(g)
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
if sb.selected == "" && len(selectable) > 0 {
|
|
|
|
sb.selected = selectable[0]
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
|
2018-09-13 13:43:47 +03:00
|
|
|
return sb.focusView(g)
|
2018-08-08 23:22:35 +03:00
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:03 +03:00
|
|
|
func (sb *showBug) left(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if sb.isOnSide {
|
|
|
|
sb.isOnSide = false
|
|
|
|
sb.selected = ""
|
2018-08-17 14:07:46 +03:00
|
|
|
return sb.selectNext(g, v)
|
2018-08-12 00:36:03 +03:00
|
|
|
}
|
|
|
|
|
2018-08-17 14:07:46 +03:00
|
|
|
if sb.selected == "" {
|
|
|
|
return sb.selectNext(g, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-08-12 00:36:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sb *showBug) right(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if !sb.isOnSide {
|
|
|
|
sb.isOnSide = true
|
|
|
|
sb.selected = ""
|
2018-08-17 14:07:46 +03:00
|
|
|
return sb.selectNext(g, v)
|
2018-08-12 00:36:03 +03:00
|
|
|
}
|
|
|
|
|
2018-08-17 14:07:46 +03:00
|
|
|
if sb.selected == "" {
|
|
|
|
return sb.selectNext(g, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-08-12 00:36:03 +03:00
|
|
|
}
|
|
|
|
|
2018-08-09 02:35:31 +03:00
|
|
|
func (sb *showBug) focusView(g *gocui.Gui) error {
|
|
|
|
mainView, err := g.View(showBugView)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, maxY := mainView.Size()
|
|
|
|
|
|
|
|
_, vy0, _, _, err := g.ViewPosition(sb.selected)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := g.View(sb.selected)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, vMaxY := v.Size()
|
|
|
|
|
|
|
|
vy1 := vy0 + vMaxY
|
|
|
|
|
|
|
|
if vy0 < 0 {
|
|
|
|
sb.scroll += vy0
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if vy1 > maxY {
|
|
|
|
sb.scroll -= maxY - vy1
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
func (sb *showBug) comment(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return addCommentWithEditor(sb.bug)
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:35:31 +03:00
|
|
|
func (sb *showBug) setTitle(g *gocui.Gui, v *gocui.View) error {
|
2018-08-02 17:35:13 +03:00
|
|
|
return setTitleWithEditor(sb.bug)
|
|
|
|
}
|
2018-08-12 03:42:03 +03:00
|
|
|
|
2018-10-02 23:14:06 +03:00
|
|
|
func (sb *showBug) toggleOpenClose(g *gocui.Gui, v *gocui.View) error {
|
2018-10-03 01:18:39 +03:00
|
|
|
switch sb.bug.Snapshot().Status {
|
|
|
|
case bug.OpenStatus:
|
2019-02-24 14:58:04 +03:00
|
|
|
_, err := sb.bug.Close()
|
|
|
|
return err
|
2018-10-03 01:18:39 +03:00
|
|
|
case bug.ClosedStatus:
|
2019-02-24 14:58:04 +03:00
|
|
|
_, err := sb.bug.Open()
|
|
|
|
return err
|
2018-10-03 01:18:39 +03:00
|
|
|
default:
|
|
|
|
return nil
|
2018-10-02 23:14:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 19:31:46 +03:00
|
|
|
func (sb *showBug) edit(g *gocui.Gui, v *gocui.View) error {
|
2018-10-04 22:22:26 +03:00
|
|
|
snap := sb.bug.Snapshot()
|
|
|
|
|
2018-10-04 19:31:46 +03:00
|
|
|
if sb.isOnSide {
|
2018-10-04 22:22:26 +03:00
|
|
|
return sb.editLabels(g, snap)
|
2018-10-04 19:31:46 +03:00
|
|
|
}
|
|
|
|
|
2019-04-11 00:53:10 +03:00
|
|
|
if sb.selected == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
op, err := snap.SearchTimelineItem(entity.Id(sb.selected))
|
2018-10-04 19:31:46 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-08 18:17:15 +03:00
|
|
|
switch op := op.(type) {
|
2018-10-04 19:31:46 +03:00
|
|
|
case *bug.AddCommentTimelineItem:
|
2020-02-08 18:17:15 +03:00
|
|
|
return editCommentWithEditor(sb.bug, op.Id(), op.Message)
|
2018-10-04 19:31:46 +03:00
|
|
|
case *bug.CreateTimelineItem:
|
2020-02-08 18:17:15 +03:00
|
|
|
return editCommentWithEditor(sb.bug, op.Id(), op.Message)
|
2018-10-04 22:22:26 +03:00
|
|
|
case *bug.LabelChangeTimelineItem:
|
|
|
|
return sb.editLabels(g, snap)
|
2018-10-04 19:31:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.msgPopup.Activate(msgPopupErrorTitle, "Selected field is not editable.")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-04 22:22:26 +03:00
|
|
|
func (sb *showBug) editLabels(g *gocui.Gui, snap *bug.Snapshot) error {
|
|
|
|
ui.labelSelect.SetBug(sb.cache, sb.bug)
|
|
|
|
return ui.activateWindow(ui.labelSelect)
|
2018-08-12 03:42:03 +03:00
|
|
|
}
|