aboutsummaryrefslogtreecommitdiffstats
path: root/commands/ls.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-11-03 14:00:35 +0100
committerMichael Muré <batolettre@gmail.com>2019-11-03 14:00:35 +0100
commitf72a9dc62ba20546b2cdeb466434fc1900741a4f (patch)
tree8b68dc12c312d0a1fe6d5b1a1388cee82d44c634 /commands/ls.go
parent809abf9244f64683fe2d9f8489a4dcff0904d5b5 (diff)
downloadgit-bug-f72a9dc62ba20546b2cdeb466434fc1900741a4f.tar.gz
switch to go-term-text to fix bad underflow for label rendering
Diffstat (limited to 'commands/ls.go')
-rw-r--r--commands/ls.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/commands/ls.go b/commands/ls.go
index 9993031b..70a948e6 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -4,11 +4,12 @@ import (
"fmt"
"strings"
+ text "github.com/MichaelMure/go-term-text"
+ "github.com/spf13/cobra"
+
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/util/colors"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/MichaelMure/git-bug/util/text"
- "github.com/spf13/cobra"
)
var (
@@ -65,21 +66,17 @@ func runLsBug(cmd *cobra.Command, args []string) error {
name = b.LegacyAuthor.DisplayName()
}
- labelsTxt := ""
- nbLabels := 0
+ var labelsTxt strings.Builder
for _, l := range b.Labels {
- lc := l.Color()
- lc256 := lc.Term256()
- nbLabels++
- if nbLabels >= 5 && len(b.Labels) > 5 {
- labelsTxt += " …"
- break
- }
- labelsTxt += lc256.Escape() + " ◼" + lc256.Unescape()
+ lc256 := l.Color().Term256()
+ labelsTxt.WriteString(lc256.Escape())
+ labelsTxt.WriteString(" ◼")
+ labelsTxt.WriteString(lc256.Unescape())
}
// truncate + pad if needed
- titleFmt := text.LeftPadMaxLine(b.Title, 50-(nbLabels*2), 0)
+ labelsFmt := text.TruncateMax(labelsTxt.String(), 10)
+ titleFmt := text.LeftPadMaxLine(b.Title, 50-text.Len(labelsFmt), 0)
authorFmt := text.LeftPadMaxLine(name, 15, 0)
comments := fmt.Sprintf("%4d 💬", b.LenComments)
@@ -90,7 +87,7 @@ func runLsBug(cmd *cobra.Command, args []string) error {
fmt.Printf("%s %s\t%s\t%s\t%s\n",
colors.Cyan(b.Id.Human()),
colors.Yellow(b.Status),
- titleFmt+labelsTxt,
+ titleFmt+labelsFmt,
colors.Magenta(authorFmt),
comments,
)