Skip to content

Commit

Permalink
show labels with color fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Sep 15, 2018
1 parent 0edf33e commit 0e843fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cmd/util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"sort"
"strconv"
"strings"
)

func StringWidthWithoutColor(s string) int {
Expand Down Expand Up @@ -77,18 +76,18 @@ func ItemTableString(items []todoist.Item, relations todoist.ItemRelations, f fu
if v, ok := relations.Projects[i.ProjectID]; ok {
project = v
}
labels := []string{}
var labels todoist.Labels
for _, lid := range i.Labels {
if v, ok := relations.Labels[lid]; ok {
labels = append(labels, v.String())
labels = append(labels, v)
}
}
rows = append(rows, []todoist.ColorStringer{
todoist.NewNoColorString(i.ID.String()),
f(i),
todoist.NewNoColorString(strconv.Itoa(i.Priority)),
project,
todoist.NewNoColorString(strings.Join(labels, " ")),
labels,
todoist.NewNoColorString(i.Content),
})
}
Expand Down
18 changes: 18 additions & 0 deletions todoist/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ func (l Label) ColorString() string {
return color.New(attr).Sprint(l.String())
}

type Labels []Label

func (ls Labels) String() string {
var arr []string
for _, l := range ls {
arr = append(arr, l.String())
}
return strings.Join(arr, " ")
}

func (ls Labels) ColorString() string {
var arr []string
for _, l := range ls {
arr = append(arr, l.ColorString())
}
return strings.Join(arr, " ")
}

type LabelClient struct {
*Client
cache *labelCache
Expand Down

0 comments on commit 0e843fd

Please sign in to comment.