termui: colors show bug

This commit is contained in:
Michael Muré 2018-08-09 14:36:23 +02:00
parent 0da2bea132
commit b6087d7e35
No known key found for this signature in database
GPG Key ID: A4457C029293126F

View File

@ -155,26 +155,22 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
sb.childViews = nil sb.childViews = nil
sb.selectableView = nil sb.selectableView = nil
v, err := g.SetView(showBugHeaderView, x0, y0, maxX+1, y0+4) header := fmt.Sprintf("[ %s ] %s\n\n[ %s ] %s opened this bug on %s",
util.Cyan(snap.HumanId()),
util.Bold(snap.Title),
util.Yellow(snap.Status),
util.Magenta(snap.Author.Name),
snap.CreatedAt.Format(timeLayout),
)
content, lines := util.TextWrap(header, maxX)
v, err := sb.createOpView(g, showBugHeaderView, x0, y0, maxX+1, lines, false)
if err != nil { if err != nil {
if err != gocui.ErrUnknownView { return err
return err
}
v.Frame = false
} }
sb.childViews = append(sb.childViews, showBugHeaderView)
y0 += 4 fmt.Fprint(v, content)
y0 += lines + 1
v.Clear()
header1 := fmt.Sprintf("[%s] %s", snap.HumanId(), snap.Title)
fmt.Fprintf(v, util.LeftPaddedString(header1, maxX-1, 0)+"\n\n")
header2 := fmt.Sprintf("[%s] %s opened this bug on %s",
snap.Status, snap.Author.Name, snap.CreatedAt.Format(timeLayout))
fmt.Fprintf(v, util.LeftPaddedString(header2, maxX-1, 0))
for i, op := range snap.Operations { for i, op := range snap.Operations {
viewName := fmt.Sprintf("op%d", i) viewName := fmt.Sprintf("op%d", i)
@ -198,17 +194,36 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
case operations.AddCommentOperation: case operations.AddCommentOperation:
comment := op.(operations.AddCommentOperation) comment := op.(operations.AddCommentOperation)
header := fmt.Sprintf("%s commented on %s", content := fmt.Sprintf("%s commented on %s\n\n%s",
comment.Author.Name, comment.Time().Format(timeLayout)) util.Magenta(comment.Author.Name),
header = util.LeftPaddedString(header, maxX, 6) comment.Time().Format(timeLayout),
message, lines := util.TextWrap(comment.Message, maxX) comment.Message,
)
content, lines := util.TextWrapPadded(content, maxX, 6)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines+2, true) v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil { if err != nil {
return err return err
} }
fmt.Fprint(v, header, "\n\n", message) fmt.Fprint(v, content)
y0 += lines + 3 y0 += lines + 2
case operations.SetTitleOperation:
setTitle := op.(operations.SetTitleOperation)
content := fmt.Sprintf("%s changed the title to %s on %s",
util.Magenta(setTitle.Author.Name),
util.Bold(setTitle.Title),
setTitle.Time().Format(timeLayout),
)
content, lines := util.TextWrap(content, maxX)
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
return err
}
fmt.Fprint(v, content)
y0 += lines + 2
} }
} }