kevinschoon-pomo/pkg/internal/util.go

81 lines
2.0 KiB
Go
Raw Permalink Normal View History

2020-09-08 18:35:47 +02:00
package pomo
2018-01-20 17:51:27 +01:00
import (
"fmt"
"time"
2018-07-12 21:03:53 +02:00
"github.com/fatih/color"
2018-01-20 17:51:27 +01:00
)
2020-09-08 18:35:47 +02:00
func SummerizeTasks(config *Config, tasks []*Task) {
2018-01-20 17:51:27 +01:00
for _, task := range tasks {
2018-02-03 19:28:29 +01:00
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))
2018-01-23 15:47:40 +01:00
// 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("[")
2018-01-23 15:47:40 +01:00
for i, pomodoro := range task.Pomodoros {
if i > 0 {
fmt.Printf(" ")
}
2018-01-23 15:47:40 +01:00
// 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 {
2018-01-23 15:47:40 +01:00
// 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(" ")
}
2018-01-23 15:47:40 +01:00
color.New(color.FgRed).Printf("X")
}
fmt.Printf("]")
2018-01-23 15:47:40 +01:00
// Tags
2018-01-20 17:51:27 +01:00
if len(task.Tags) > 0 {
fmt.Printf(" [")
2018-01-20 17:51:27 +01:00
for i, tag := range task.Tags {
2018-03-03 21:19:30 +01:00
if i > 0 && i != len(task.Tags) {
2018-01-23 15:47:40 +01:00
fmt.Printf(" ")
}
// user specified color mapping exists
2020-09-08 06:20:42 +02:00
if config.Colors != nil {
if color := config.Colors.Get(tag); color != nil {
color.Printf("%s", tag)
} else {
// no color mapping for tag
fmt.Printf("%s", tag)
}
2018-01-23 15:47:40 +01:00
} else {
// no color mapping
fmt.Printf("%s", tag)
2018-01-20 17:51:27 +01:00
}
2020-09-08 06:20:42 +02:00
2018-01-20 17:51:27 +01:00
}
fmt.Printf("]")
2018-01-20 17:51:27 +01:00
}
fmt.Printf(" - %s", task.Message)
fmt.Printf("\n")
2018-01-20 17:51:27 +01:00
}
}
func FormatStatus(status Status) string {
state := "?"
if status.State >= RUNNING {
state = string(status.State.String()[0])
}
if status.State == RUNNING {
return fmt.Sprintf("%s [%d/%d] %s", state, status.Count, status.NPomodoros, status.Remaining)
} else {
return fmt.Sprintf("%s [%d/%d] -", state, status.Count, status.NPomodoros)
}
}