improve listed output
This commit is contained in:
parent
6b76898db2
commit
be7b387259
5
types.go
5
types.go
|
@ -116,6 +116,11 @@ type Pomodoro struct {
|
||||||
End time.Time `json:"end"`
|
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
|
// Notifier implements a system specific
|
||||||
// notification. On Linux this libnotify.
|
// notification. On Linux this libnotify.
|
||||||
// TODO: OSX, Windows(?)
|
// TODO: OSX, Windows(?)
|
||||||
|
|
32
util.go
32
util.go
|
@ -31,28 +31,44 @@ func prompt(text 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))
|
fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second))
|
||||||
// a list of green/red pomodoros
|
// a list of green/yellow/red pomodoros
|
||||||
// green[x x] red[x x]
|
// green indicates the pomodoro was finished normally
|
||||||
|
// yellow indicates the break was exceeded by +5minutes
|
||||||
|
// red indicates the pomodoro was never completed
|
||||||
fmt.Printf("[")
|
fmt.Printf("[")
|
||||||
for i := 0; i < task.NPomodoros; i++ {
|
for i, pomodoro := range task.Pomodoros {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
fmt.Printf(" ")
|
fmt.Printf(" ")
|
||||||
}
|
}
|
||||||
if len(task.Pomodoros) >= i {
|
// pomodoro exceeded it's expected duration by more than 5m
|
||||||
color.New(color.FgGreen).Printf("X")
|
if pomodoro.Duration() > task.Duration+5*time.Minute {
|
||||||
|
color.New(color.FgYellow).Printf("X")
|
||||||
} else {
|
} else {
|
||||||
|
// 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")
|
color.New(color.FgRed).Printf("X")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fmt.Printf("]")
|
fmt.Printf("]")
|
||||||
|
// Tags
|
||||||
if len(task.Tags) > 0 {
|
if len(task.Tags) > 0 {
|
||||||
fmt.Printf(" [")
|
fmt.Printf(" [")
|
||||||
for i, tag := range task.Tags {
|
for i, tag := range task.Tags {
|
||||||
if color, ok := config.Colors[tag]; ok {
|
if i > 1 && i != len(task.Tags) {
|
||||||
if i > 0 {
|
|
||||||
fmt.Printf(" ")
|
fmt.Printf(" ")
|
||||||
}
|
}
|
||||||
|
// user specified color mapping exists
|
||||||
|
if color, ok := config.Colors[tag]; ok {
|
||||||
color.Printf("%s", tag)
|
color.Printf("%s", tag)
|
||||||
|
} else {
|
||||||
|
// no color mapping
|
||||||
|
fmt.Printf("%s", tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("]")
|
fmt.Printf("]")
|
||||||
|
|
Loading…
Reference in New Issue