Merge pull request #705 from GlancingMind/compact-ls-format

Command ls: Add compact format
This commit is contained in:
Michael Muré 2021-12-04 12:37:48 +01:00 committed by GitHub
commit d1adc163bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,6 +133,8 @@ func runLs(env *Env, opts lsOptions, args []string) error {
return lsPlainFormatter(env, bugExcerpt)
case "json":
return lsJsonFormatter(env, bugExcerpt)
case "compact":
return lsCompactFormatter(env, bugExcerpt)
case "default":
return lsDefaultFormatter(env, bugExcerpt)
default:
@ -203,6 +205,32 @@ func lsJsonFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
return nil
}
func lsCompactFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
author, err := env.backend.ResolveIdentityExcerpt(b.AuthorId)
if err != nil {
return err
}
var labelsTxt strings.Builder
for _, l := range b.Labels {
lc256 := l.Color().Term256()
labelsTxt.WriteString(lc256.Escape())
labelsTxt.WriteString("◼")
labelsTxt.WriteString(lc256.Unescape())
}
env.out.Printf("%s %s %s %s %s\n",
colors.Cyan(b.Id.Human()),
colors.Yellow(b.Status),
text.LeftPadMaxLine(strings.TrimSpace(b.Title), 40, 0),
text.LeftPadMaxLine(labelsTxt.String(), 5, 0),
colors.Magenta(text.TruncateMax(author.DisplayName(), 15)),
)
}
return nil
}
func lsDefaultFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
author, err := env.backend.ResolveIdentityExcerpt(b.AuthorId)