From 25b1516968eeefc4e6fc5a27a1703ac4ff598b99 Mon Sep 17 00:00:00 2001 From: ludovicm67 Date: Tue, 15 Oct 2019 12:25:44 +0200 Subject: termui: add labels colors in bug table --- termui/bug_table.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'termui/bug_table.go') diff --git a/termui/bug_table.go b/termui/bug_table.go index 8d69d665..01269df8 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -275,8 +275,8 @@ func (bt *bugTable) getColumnWidths(maxX int) map[string]int { left := maxX - 5 - m["id"] - m["status"] - m["summary"] = 10 - left -= m["summary"] + m["comments"] = 10 + left -= m["comments"] m["lastEdit"] = 19 left -= m["lastEdit"] @@ -290,10 +290,19 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { columnWidths := bt.getColumnWidths(maxX) for _, excerpt := range bt.excerpts { - summaryTxt := fmt.Sprintf("C:%-2d L:%-2d", - excerpt.LenComments, - len(excerpt.Labels), - ) + summaryTxt := fmt.Sprintf("%4d 💬", excerpt.LenComments) + labelsTxt := "" // fmt.Sprintf("L:%-2d", len(excerpt.Labels)) + + nbLabels := 0 + for _, l := range excerpt.Labels { + lc := l.Color() + lc256 := lc.Term256() + labelsTxt += lc256.Escape() + " ◼" + lc256.Unescape() + nbLabels++ + if nbLabels >= 5 { + break + } + } var authorDisplayName string if excerpt.AuthorId != "" { @@ -310,9 +319,9 @@ 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"], 1) + title := text.LeftPadMaxLine(excerpt.Title, columnWidths["title"]-(nbLabels*2), 1) + labelsTxt author := text.LeftPadMaxLine(authorDisplayName, columnWidths["author"], 1) - summary := text.LeftPadMaxLine(summaryTxt, columnWidths["summary"], 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", @@ -320,7 +329,7 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { colors.Yellow(status), title, colors.Magenta(author), - summary, + comments, lastEdit, ) } @@ -333,12 +342,11 @@ func (bt *bugTable) renderHeader(v *gocui.View, maxX int) { status := text.LeftPadMaxLine("STATUS", columnWidths["status"], 1) title := text.LeftPadMaxLine("TITLE", columnWidths["title"], 1) author := text.LeftPadMaxLine("AUTHOR", columnWidths["author"], 1) - summary := text.LeftPadMaxLine("SUMMARY", columnWidths["summary"], 1) + comments := text.LeftPadMaxLine("COMMENTS", columnWidths["comments"], 1) lastEdit := text.LeftPadMaxLine("LAST EDIT", columnWidths["lastEdit"], 1) _, _ = fmt.Fprintf(v, "\n") - _, _ = fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, summary, lastEdit) - + _, _ = fmt.Fprintf(v, "%s %s %s %s %s %s\n", id, status, title, author, comments, lastEdit) } func (bt *bugTable) renderFooter(v *gocui.View, maxX int) { -- cgit From c9e824152d3d32a654e54bb7e9939f19b6b835ac Mon Sep 17 00:00:00 2001 From: ludovicm67 Date: Wed, 16 Oct 2019 23:51:11 +0200 Subject: termui: better overflow management --- termui/bug_table.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'termui/bug_table.go') diff --git a/termui/bug_table.go b/termui/bug_table.go index 01269df8..236aa17d 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -291,17 +291,21 @@ func (bt *bugTable) render(v *gocui.View, maxX int) { for _, excerpt := range bt.excerpts { summaryTxt := fmt.Sprintf("%4d 💬", excerpt.LenComments) - labelsTxt := "" // fmt.Sprintf("L:%-2d", len(excerpt.Labels)) + if excerpt.LenComments > 9999 { + summaryTxt = " ∞ 💬" + } + labelsTxt := "" nbLabels := 0 for _, l := range excerpt.Labels { lc := l.Color() lc256 := lc.Term256() - labelsTxt += lc256.Escape() + " ◼" + lc256.Unescape() nbLabels++ - if nbLabels >= 5 { + if nbLabels >= 5 && len(excerpt.Labels) > 5 { + labelsTxt += " …" break } + labelsTxt += lc256.Escape() + " ◼" + lc256.Unescape() } var authorDisplayName string -- cgit From f72a9dc62ba20546b2cdeb466434fc1900741a4f Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 3 Nov 2019 14:00:35 +0100 Subject: switch to go-term-text to fix bad underflow for label rendering --- termui/bug_table.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'termui/bug_table.go') 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, -- cgit