2018-01-20 17:51:27 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-01-20 19:54:30 +01:00
|
|
|
"github.com/fatih/color"
|
2018-01-20 17:51:27 +01:00
|
|
|
"os"
|
|
|
|
"os/user"
|
2018-01-20 19:54:30 +01:00
|
|
|
"time"
|
2018-01-20 17:51:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func maybe(err error) {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error:\n%s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfigPath() string {
|
|
|
|
u, err := user.Current()
|
|
|
|
maybe(err)
|
|
|
|
return u.HomeDir + "/.pomo"
|
|
|
|
}
|
|
|
|
|
|
|
|
func summerizeTasks(config *Config, tasks []*Task) {
|
|
|
|
for _, task := range tasks {
|
2018-01-20 19:54:30 +01:00
|
|
|
fmt.Printf("%d: [%s] ", task.ID, 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
|
2018-01-20 19:54:30 +01:00
|
|
|
fmt.Printf("[")
|
2018-01-23 15:47:40 +01:00
|
|
|
for i, pomodoro := range task.Pomodoros {
|
2018-01-20 19:54:30 +01:00
|
|
|
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")
|
2018-01-20 19:54:30 +01:00
|
|
|
} 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-20 19:54:30 +01:00
|
|
|
}
|
2018-01-23 15:47:40 +01:00
|
|
|
color.New(color.FgRed).Printf("X")
|
2018-01-20 19:54:30 +01:00
|
|
|
}
|
|
|
|
fmt.Printf("]")
|
2018-01-23 15:47:40 +01:00
|
|
|
// Tags
|
2018-01-20 17:51:27 +01:00
|
|
|
if len(task.Tags) > 0 {
|
2018-01-20 19:54:30 +01:00
|
|
|
fmt.Printf(" [")
|
2018-01-20 17:51:27 +01:00
|
|
|
for i, tag := range task.Tags {
|
2018-01-23 15:47:40 +01:00
|
|
|
if i > 1 && i != len(task.Tags) {
|
|
|
|
fmt.Printf(" ")
|
|
|
|
}
|
|
|
|
// user specified color mapping exists
|
2018-01-20 17:51:27 +01:00
|
|
|
if color, ok := config.Colors[tag]; ok {
|
2018-01-20 19:54:30 +01:00
|
|
|
color.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
|
|
|
}
|
|
|
|
}
|
2018-01-20 19:54:30 +01:00
|
|
|
fmt.Printf("]")
|
2018-01-20 17:51:27 +01:00
|
|
|
}
|
2018-01-20 19:54:30 +01:00
|
|
|
fmt.Printf(" - %s", task.Message)
|
|
|
|
fmt.Printf("\n")
|
2018-01-20 17:51:27 +01:00
|
|
|
}
|
|
|
|
}
|