From be7b3872599493ff66f853116ee2a643150b18d4 Mon Sep 17 00:00:00 2001 From: Kevin Schoon Date: Tue, 23 Jan 2018 22:47:40 +0800 Subject: [PATCH] improve listed output --- types.go | 5 +++++ util.go | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/types.go b/types.go index 6fdbf84..212fc73 100644 --- a/types.go +++ b/types.go @@ -116,6 +116,11 @@ type Pomodoro struct { End time.Time `json:"end"` } +// Duration returns the runtime of the pomodoro +func (p Pomodoro) Duration() time.Duration { + return (p.End.Sub(p.Start)) +} + // Notifier implements a system specific // notification. On Linux this libnotify. // TODO: OSX, Windows(?) diff --git a/util.go b/util.go index 6ff64eb..99d3f53 100644 --- a/util.go +++ b/util.go @@ -31,28 +31,44 @@ func prompt(text string) { func summerizeTasks(config *Config, tasks []*Task) { for _, task := range tasks { fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second)) - // a list of green/red pomodoros - // green[x x] red[x x] + // a list of green/yellow/red pomodoros + // green indicates the pomodoro was finished normally + // yellow indicates the break was exceeded by +5minutes + // red indicates the pomodoro was never completed fmt.Printf("[") - for i := 0; i < task.NPomodoros; i++ { + for i, pomodoro := range task.Pomodoros { if i > 0 { fmt.Printf(" ") } - if len(task.Pomodoros) >= i { - color.New(color.FgGreen).Printf("X") + // pomodoro exceeded it's expected duration by more than 5m + if pomodoro.Duration() > task.Duration+5*time.Minute { + color.New(color.FgYellow).Printf("X") } else { - color.New(color.FgRed).Printf("X") + // pomodoro completed normally + color.New(color.FgGreen).Printf("X") } } + // each missed pomodoro + for i := 0; i < task.NPomodoros-len(task.Pomodoros); i++ { + if i > 0 || i == 0 && len(task.Pomodoros) > 0 { + fmt.Printf(" ") + } + color.New(color.FgRed).Printf("X") + } fmt.Printf("]") + // Tags if len(task.Tags) > 0 { fmt.Printf(" [") for i, tag := range task.Tags { + if i > 1 && i != len(task.Tags) { + fmt.Printf(" ") + } + // user specified color mapping exists if color, ok := config.Colors[tag]; ok { - if i > 0 { - fmt.Printf(" ") - } color.Printf("%s", tag) + } else { + // no color mapping + fmt.Printf("%s", tag) } } fmt.Printf("]")