add date/time in task list output

This commit is contained in:
Kevin Schoon 2018-02-03 13:28:29 -05:00
parent 38c5700812
commit 987fbfd261
3 changed files with 24 additions and 4 deletions

View File

@ -74,7 +74,8 @@ func list(path *string) func(*cli.Cmd) {
maybe(json.NewEncoder(os.Stdout).Encode(tasks)) maybe(json.NewEncoder(os.Stdout).Encode(tasks))
return return
} }
config, _ := NewConfig(*path + "/config.json") config, err := NewConfig(*path + "/config.json")
maybe(err)
summerizeTasks(config, tasks) summerizeTasks(config, tasks)
} }
} }

View File

@ -11,6 +11,10 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
) )
const (
defaultDateTimeFmt = "2006-01-02 15:04"
)
type State int type State int
func (s State) String() string { func (s State) String() string {
@ -58,6 +62,7 @@ func (w *Wheel) String() string {
// Config represents user preferences // Config represents user preferences
type Config struct { type Config struct {
Colors map[string]*color.Color Colors map[string]*color.Color
DateTimeFmt string
} }
var colorMap = map[string]*color.Color{ var colorMap = map[string]*color.Color{
@ -70,6 +75,7 @@ var colorMap = map[string]*color.Color{
func (c *Config) UnmarshalJSON(raw []byte) error { func (c *Config) UnmarshalJSON(raw []byte) error {
config := &struct { config := &struct {
Colors map[string]string `json:"colors"` Colors map[string]string `json:"colors"`
DateTimeFmt string `json:"datetimefmt"`
}{} }{}
err := json.Unmarshal(raw, config) err := json.Unmarshal(raw, config)
if err != nil { if err != nil {
@ -82,6 +88,11 @@ func (c *Config) UnmarshalJSON(raw []byte) error {
return fmt.Errorf("bad color choice: %s", name) return fmt.Errorf("bad color choice: %s", name)
} }
} }
if config.DateTimeFmt != "" {
c.DateTimeFmt = config.DateTimeFmt
} else {
c.DateTimeFmt = defaultDateTimeFmt
}
return nil return nil
} }
@ -100,6 +111,10 @@ func NewConfig(path string) (*Config, error) {
config := &Config{ config := &Config{
Colors: map[string]*color.Color{}, Colors: map[string]*color.Color{},
} }
err = json.Unmarshal(raw, config)
if err != nil {
return nil, err
}
return config, json.Unmarshal(raw, config) return config, json.Unmarshal(raw, config)
} }

View File

@ -23,7 +23,11 @@ func defaultConfigPath() string {
func summerizeTasks(config *Config, tasks []*Task) { func summerizeTasks(config *Config, tasks []*Task) {
for _, task := range tasks { for _, task := range tasks {
fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second)) var start string
if len(task.Pomodoros) > 0 {
start = task.Pomodoros[0].Start.Format(config.DateTimeFmt)
}
fmt.Printf("%d: [%s] [%s] ", task.ID, start, task.Duration.Truncate(time.Second))
// a list of green/yellow/red pomodoros // a list of green/yellow/red pomodoros
// green indicates the pomodoro was finished normally // green indicates the pomodoro was finished normally
// yellow indicates the break was exceeded by +5minutes // yellow indicates the break was exceeded by +5minutes