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 /commands | |
parent | 809abf9244f64683fe2d9f8489a4dcff0904d5b5 (diff) | |
download | git-bug-f72a9dc62ba20546b2cdeb466434fc1900741a4f.tar.gz |
switch to go-term-text to fix bad underflow for label rendering
Diffstat (limited to 'commands')
-rw-r--r-- | commands/bridge.go | 3 | ||||
-rw-r--r-- | commands/comment.go | 7 | ||||
-rw-r--r-- | commands/label_rm.go | 3 | ||||
-rw-r--r-- | commands/ls.go | 25 | ||||
-rw-r--r-- | commands/select.go | 3 |
5 files changed, 21 insertions, 20 deletions
diff --git a/commands/bridge.go b/commands/bridge.go index 2566fd06..3c398e6b 100644 --- a/commands/bridge.go +++ b/commands/bridge.go @@ -3,10 +3,11 @@ package commands import ( "fmt" + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) func runBridge(cmd *cobra.Command, args []string) error { diff --git a/commands/comment.go b/commands/comment.go index 33bae65d..4be39a84 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -3,13 +3,14 @@ package commands import ( "fmt" + "github.com/MichaelMure/go-term-text" + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/commands/select" "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" ) func runComment(cmd *cobra.Command, args []string) error { @@ -41,7 +42,7 @@ func commentsTextOutput(comments []bug.Comment) { fmt.Printf("Author: %s\n", colors.Magenta(comment.Author.DisplayName())) fmt.Printf("Id: %s\n", colors.Cyan(comment.Id().Human())) fmt.Printf("Date: %s\n\n", comment.FormatTime()) - fmt.Println(text.LeftPad(comment.Message, 4)) + fmt.Println(text.LeftPadLines(comment.Message, 4)) } } diff --git a/commands/label_rm.go b/commands/label_rm.go index a0c1c56d..11300c78 100644 --- a/commands/label_rm.go +++ b/commands/label_rm.go @@ -3,10 +3,11 @@ package commands import ( "fmt" + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) func runLabelRm(cmd *cobra.Command, args []string) error { 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, ) diff --git a/commands/select.go b/commands/select.go index 7c40df5c..f2ae33ca 100644 --- a/commands/select.go +++ b/commands/select.go @@ -4,10 +4,11 @@ import ( "errors" "fmt" + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) func runSelect(cmd *cobra.Command, args []string) error { |