kevinschoon-pomo/util.go

57 lines
1.0 KiB
Go
Raw Normal View History

2018-01-20 17:51:27 +01:00
package main
import (
"fmt"
"github.com/fatih/color"
2018-01-20 17:51:27 +01:00
"os"
"os/user"
"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 {
fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second))
// a list of green/red pomodoros
// green[x x] red[x x]
fmt.Printf("[")
for i := 0; i < task.NPomodoros; i++ {
if i > 0 {
fmt.Printf(" ")
}
if len(task.Pomodoros) >= i {
color.New(color.FgGreen).Printf("X")
} else {
color.New(color.FgRed).Printf("X")
}
}
fmt.Printf("]")
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 {
if color, ok := config.Colors[tag]; ok {
if i > 0 {
fmt.Printf(" ")
2018-01-20 17:51:27 +01:00
}
color.Printf("%s", tag)
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
}
}