diff options
-rw-r--r-- | commands/ls.go | 47 | ||||
-rw-r--r-- | termui/bug_table.go | 2 |
2 files changed, 30 insertions, 19 deletions
diff --git a/commands/ls.go b/commands/ls.go index ad61a852..4431e0d4 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -3,6 +3,7 @@ package commands import ( "encoding/json" "fmt" + "regexp" "strings" "time" @@ -76,8 +77,6 @@ git bug ls --status closed --by creation } func runLs(env *Env, opts lsOptions, args []string) error { - time.Sleep(5 * time.Second) - var q *query.Query var err error @@ -210,7 +209,7 @@ func lsDefaultFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { // truncate + pad if needed labelsFmt := text.TruncateMax(labelsTxt.String(), 10) - titleFmt := text.LeftPadMaxLine(b.Title, 50-text.Len(labelsFmt), 0) + titleFmt := text.LeftPadMaxLine(strings.TrimSpace(b.Title), 50-text.Len(labelsFmt), 0) authorFmt := text.LeftPadMaxLine(name, 15, 0) comments := fmt.Sprintf("%4d 💬", b.LenComments) @@ -231,20 +230,30 @@ func lsDefaultFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { func lsPlainFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { for _, b := range bugExcerpts { - env.out.Printf("%s [%s] %s\n", b.Id.Human(), b.Status, b.Title) + env.out.Printf("%s [%s] %s\n", b.Id.Human(), b.Status, strings.TrimSpace(b.Title)) } return nil } func lsOrgmodeFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { - env.out.Println("+TODO: OPEN | CLOSED") + // see https://orgmode.org/manual/Tags.html + orgTagRe := regexp.MustCompile("[^[:alpha:]_@]") + formatTag := func(l bug.Label) string { + return orgTagRe.ReplaceAllString(l.String(), "_") + } + + formatTime := func(time time.Time) string { + return time.Format("[2006-01-02 Mon 15:05]") + } + + env.out.Println("#+TODO: OPEN | CLOSED") for _, b := range bugExcerpts { - status := strings.Title(b.Status.String()) + status := strings.ToUpper(b.Status.String()) var title string if link, ok := b.CreateMetadata["github-url"]; ok { - title = fmt.Sprintf("[%s][%s]", link, b.Title) + title = fmt.Sprintf("[[%s][%s]]", link, b.Title) } else { title = b.Title } @@ -260,24 +269,26 @@ func lsOrgmodeFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error { name = b.LegacyAuthor.DisplayName() } - labels := b.Labels - var labelsString string - if len(labels) > 0 { - labelsString = fmt.Sprintf(":%s:", strings.Replace(fmt.Sprint(labels), " ", ":", -1)) - } else { - labelsString = "" + var labels strings.Builder + labels.WriteString(":") + for i, l := range b.Labels { + if i > 0 { + labels.WriteString(":") + } + labels.WriteString(formatTag(l)) } + labels.WriteString(":") - env.out.Printf("* %s %s [%s] %s: %s %s\n", - b.Id.Human(), + env.out.Printf("* %-6s %s %s %s: %s %s\n", status, - b.CreateTime(), + b.Id.Human(), + formatTime(b.CreateTime()), name, title, - labelsString, + labels.String(), ) - env.out.Printf("** Last Edited: %s\n", b.EditTime().String()) + env.out.Printf("** Last Edited: %s\n", formatTime(b.EditTime())) env.out.Printf("** Actors:\n") for _, element := range b.Actors { diff --git a/termui/bug_table.go b/termui/bug_table.go index e2c1049f..4c7ade77 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -320,7 +320,7 @@ 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) labels := text.TruncateMax(labelsTxt.String(), minInt(columnWidths["title"]-2, 10)) - title := text.LeftPadMaxLine(excerpt.Title, columnWidths["title"]-text.Len(labels), 1) + title := text.LeftPadMaxLine(strings.TrimSpace(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) |