aboutsummaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-23 21:46:47 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-23 21:46:47 +0100
commit94b28b68e57cf683731467b73b3ba777d1e4f86d (patch)
tree491a67e1d148fb661c0137b180d8251ea5ee3cc3 /termui
parent7454b9505ae2d680293d3d00d72df14f36f4e616 (diff)
downloadgit-bug-94b28b68e57cf683731467b73b3ba777d1e4f86d.tar.gz
termui: display an explicit placeholder for empty messages
Diffstat (limited to 'termui')
-rw-r--r--termui/show_bug.go39
1 files changed, 29 insertions, 10 deletions
diff --git a/termui/show_bug.go b/termui/show_bug.go
index cb2fe04c..a1f4b3fe 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -95,7 +95,7 @@ func (sb *showBug) layout(g *gocui.Gui) error {
}
v.Clear()
- fmt.Fprintf(v, "[q] Save and return [←↓↑→,hjkl] Navigation [o] Toggle open/close [e] Edit [c] Comment [t] Change title")
+ _, _ = fmt.Fprintf(v, "[q] Save and return [←↓↑→,hjkl] Navigation [o] Toggle open/close [e] Edit [c] Comment [t] Change title")
_, err = g.SetViewOnTop(showBugInstructionView)
if err != nil {
@@ -228,7 +228,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
return err
}
- fmt.Fprint(v, bugHeader)
+ _, _ = fmt.Fprint(v, bugHeader)
y0 += lines + 1
for _, op := range snap.Timeline {
@@ -241,13 +241,21 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
case *bug.CreateTimelineItem:
create := op.(*bug.CreateTimelineItem)
- content, lines := text.WrapLeftPadded(create.Message, maxX-1, 4)
+
+ var content string
+ var lines int
+
+ if create.MessageIsEmpty() {
+ content, lines = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4)
+ } else {
+ content, lines = text.WrapLeftPadded(create.Message, maxX-1, 4)
+ }
v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true)
if err != nil {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
y0 += lines + 2
case *bug.AddCommentTimelineItem:
@@ -258,7 +266,13 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
edited = " (edited)"
}
- message, _ := text.WrapLeftPadded(comment.Message, maxX-1, 4)
+ var message string
+ if comment.MessageIsEmpty() {
+ message, _ = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4)
+ } else {
+ message, _ = text.WrapLeftPadded(comment.Message, maxX-1, 4)
+ }
+
content := fmt.Sprintf("%s commented on %s%s\n\n%s",
colors.Magenta(comment.Author.DisplayName()),
comment.CreatedAt.Time().Format(timeLayout),
@@ -271,7 +285,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
if err != nil {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
y0 += lines + 2
case *bug.SetTitleTimelineItem:
@@ -288,7 +302,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
if err != nil {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
y0 += lines + 2
case *bug.SetStatusTimelineItem:
@@ -305,7 +319,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
if err != nil {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
y0 += lines + 2
case *bug.LabelChangeTimelineItem:
@@ -354,7 +368,7 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
if err != nil {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
y0 += lines + 2
}
}
@@ -362,6 +376,11 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error {
return nil
}
+// emptyMessagePlaceholder return a formatted placeholder for an empty message
+func emptyMessagePlaceholder() string {
+ return colors.GreyBold("No description provided.")
+}
+
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)
@@ -423,7 +442,7 @@ func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
return err
}
- fmt.Fprint(v, content)
+ _, _ = fmt.Fprint(v, content)
return nil
}