diff --git a/main.go b/main.go index a3fcce6..402024a 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,8 @@ func list(path *string) func(*cli.Cmd) { maybe(json.NewEncoder(os.Stdout).Encode(tasks)) return } - config, _ := NewConfig(*path + "/config.json") + config, err := NewConfig(*path + "/config.json") + maybe(err) summerizeTasks(config, tasks) } } diff --git a/types.go b/types.go index a6d03ca..ad2d072 100644 --- a/types.go +++ b/types.go @@ -11,6 +11,10 @@ import ( "github.com/fatih/color" ) +const ( + defaultDateTimeFmt = "2006-01-02 15:04" +) + type State int func (s State) String() string { @@ -57,7 +61,8 @@ func (w *Wheel) String() string { // Config represents user preferences type Config struct { - Colors map[string]*color.Color + Colors map[string]*color.Color + DateTimeFmt string } var colorMap = map[string]*color.Color{ @@ -69,7 +74,8 @@ var colorMap = map[string]*color.Color{ func (c *Config) UnmarshalJSON(raw []byte) error { config := &struct { - Colors map[string]string `json:"colors"` + Colors map[string]string `json:"colors"` + DateTimeFmt string `json:"datetimefmt"` }{} err := json.Unmarshal(raw, config) if err != nil { @@ -82,6 +88,11 @@ func (c *Config) UnmarshalJSON(raw []byte) error { return fmt.Errorf("bad color choice: %s", name) } } + if config.DateTimeFmt != "" { + c.DateTimeFmt = config.DateTimeFmt + } else { + c.DateTimeFmt = defaultDateTimeFmt + } return nil } @@ -100,6 +111,10 @@ func NewConfig(path string) (*Config, error) { config := &Config{ Colors: map[string]*color.Color{}, } + err = json.Unmarshal(raw, config) + if err != nil { + return nil, err + } return config, json.Unmarshal(raw, config) } diff --git a/util.go b/util.go index a98185d..a2de6ec 100644 --- a/util.go +++ b/util.go @@ -23,7 +23,11 @@ func defaultConfigPath() string { func summerizeTasks(config *Config, tasks []*Task) { 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 // green indicates the pomodoro was finished normally // yellow indicates the break was exceeded by +5minutes