Skip to content

Commit

Permalink
color due date
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Feb 19, 2017
1 parent 2dfcab0 commit dd7cca4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/todoist/cmd/today.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cmd

import (
"github.com/fatih/color"
"github.com/kobtea/go-todoist/todoist"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"os"
"sort"
"strconv"
"strings"
"time"
)

// todayCmd represents the today command
Expand All @@ -25,7 +25,7 @@ var todayCmd = &cobra.Command{
return items[i].DueDateUtc.Before(items[j].DueDateUtc)
})
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"due", "id", "date", "pri", "project", "labels", "content"})
table.SetHeader([]string{"id", "date", "pri", "project", "labels", "content"})
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
for _, i := range items {
var project string
Expand All @@ -38,16 +38,13 @@ var todayCmd = &cobra.Command{
labels = append(labels, j.String())
}
}
var d string
if i.DueDateUtc.Before(todoist.Time{time.Now().UTC()}) {
d = "overdue"
} else {
d = "today"
date := i.DateString
if i.IsOverDueDate() {
date = color.New(color.BgRed).SprintFunc()(date)
}
table.Append([]string{
d,
i.ID.String(),
i.DateString,
date,
strconv.Itoa(i.Priority),
project,
strings.Join(labels, " "),
Expand Down
5 changes: 5 additions & 0 deletions todoist/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/url"
"time"
)

type Item struct {
Expand All @@ -31,6 +32,10 @@ type Item struct {
DateAdded Time `json:"date_added,omitempty"`
}

func (i Item) IsOverDueDate() bool {
return i.DueDateUtc.Before(Time{time.Now().UTC()})
}

type ItemClient struct {
*Client
cache *itemCache
Expand Down

0 comments on commit dd7cca4

Please sign in to comment.