diff options
author | Michael Muré <batolettre@gmail.com> | 2019-11-03 14:00:35 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-11-03 14:00:35 +0100 |
commit | f72a9dc62ba20546b2cdeb466434fc1900741a4f (patch) | |
tree | 8b68dc12c312d0a1fe6d5b1a1388cee82d44c634 /termui | |
parent | 809abf9244f64683fe2d9f8489a4dcff0904d5b5 (diff) | |
download | git-bug-f72a9dc62ba20546b2cdeb466434fc1900741a4f.tar.gz |
switch to go-term-text to fix bad underflow for label rendering
Diffstat (limited to 'termui')
-rw-r--r-- | termui/bug_table.go | 32 | ||||
-rw-r--r-- | termui/label_select.go | 3 | ||||
-rw-r--r-- | termui/msg_popup.go | 2 | ||||
-rw-r--r-- | termui/show_bug.go | 5 |
4 files changed, 23 insertions, 19 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go index 236aa17d..c432c94a 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -3,14 +3,16 @@ package termui import ( "bytes" "fmt" + "strings" "time" + "github.com/MichaelMure/go-term-text" + "github.com/MichaelMure/gocui" + "github.com/dustin/go-humanize" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/util/colors" - "github.com/MichaelMure/git-bug/util/text" - "github.com/MichaelMure/gocui" - "github.com/dustin/go-humanize" ) const bugTableView = "bugTableView" @@ -291,21 +293,19 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { for _, excerpt := range bt.excerpts { summaryTxt := fmt.Sprintf("%4d 💬", excerpt.LenComments) + if excerpt.LenComments <= 0 { + summaryTxt = "" + } if excerpt.LenComments > 9999 { summaryTxt = " ∞ 💬" } - labelsTxt := "" - nbLabels := 0 + var labelsTxt strings.Builder for _, l := range excerpt.Labels { - lc := l.Color() - lc256 := lc.Term256() - nbLabels++ - if nbLabels >= 5 && len(excerpt.Labels) > 5 { - labelsTxt += " …" - break - } - labelsTxt += lc256.Escape() + " ◼" + lc256.Unescape() + lc256 := l.Color().Term256() + labelsTxt.WriteString(lc256.Escape()) + labelsTxt.WriteString(" ◼") + labelsTxt.WriteString(lc256.Unescape()) } var authorDisplayName string @@ -323,15 +323,17 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { id := text.LeftPadMaxLine(excerpt.Id.Human(), columnWidths["id"], 1) status := text.LeftPadMaxLine(excerpt.Status.String(), columnWidths["status"], 1) - title := text.LeftPadMaxLine(excerpt.Title, columnWidths["title"]-(nbLabels*2), 1) + labelsTxt + labels := text.TruncateMax(labelsTxt.String(), minInt(columnWidths["title"]-2, 10)) + title := text.LeftPadMaxLine(excerpt.Title, columnWidths["title"]-text.Len(labels), 1) author := text.LeftPadMaxLine(authorDisplayName, columnWidths["author"], 1) comments := text.LeftPadMaxLine(summaryTxt, columnWidths["comments"], 1) lastEdit := text.LeftPadMaxLine(humanize.Time(lastEditTime), columnWidths["lastEdit"], 1) - _, _ = fmt.Fprintf(v, "%s %s %s %s %s %s\n", + _, _ = fmt.Fprintf(v, "%s %s %s%s %s %s %s\n", colors.Cyan(id), colors.Yellow(status), title, + labels, colors.Magenta(author), comments, lastEdit, diff --git a/termui/label_select.go b/termui/label_select.go index e0f97279..39edbdb1 100644 --- a/termui/label_select.go +++ b/termui/label_select.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + "github.com/MichaelMure/gocui" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/gocui" ) const labelSelectView = "labelSelectView" diff --git a/termui/msg_popup.go b/termui/msg_popup.go index 4452427e..99180c99 100644 --- a/termui/msg_popup.go +++ b/termui/msg_popup.go @@ -3,7 +3,7 @@ package termui import ( "fmt" - "github.com/MichaelMure/git-bug/util/text" + "github.com/MichaelMure/go-term-text" "github.com/MichaelMure/gocui" ) diff --git a/termui/show_bug.go b/termui/show_bug.go index f9a30b4b..50478b8f 100644 --- a/termui/show_bug.go +++ b/termui/show_bug.go @@ -5,12 +5,13 @@ import ( "fmt" "strings" + "github.com/MichaelMure/go-term-text" + "github.com/MichaelMure/gocui" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/util/colors" - "github.com/MichaelMure/git-bug/util/text" - "github.com/MichaelMure/gocui" ) const showBugView = "showBugView" |