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))
return
}
config, _ := NewConfig(*path + "/config.json")
config, err := NewConfig(*path + "/config.json")
maybe(err)
summerizeTasks(config, tasks)
}
}

View File

@ -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)
}

View File

@ -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