1 | package main
|
2 |
|
3 | import (
|
4 | "bufio"
|
5 | "fmt"
|
6 | "github.com/fatih/color"
|
7 | "os"
|
8 | "os/user"
|
9 | "time"
|
10 | )
|
11 |
|
12 | func maybe(err error) {
|
13 | if err != nil {
|
14 | fmt.Printf("Error:\n%s\n", err)
|
15 | os.Exit(1)
|
16 | }
|
17 | }
|
18 |
|
19 | func defaultConfigPath() string {
|
20 | u, err := user.Current()
|
21 | maybe(err)
|
22 | return u.HomeDir + "/.pomo"
|
23 | }
|
24 |
|
25 | func prompt(text string) {
|
26 | reader := bufio.NewReader(os.Stdin)
|
27 | fmt.Println(text)
|
28 | reader.ReadString('\n')
|
29 | }
|
30 |
|
31 | func summerizeTasks(config *Config, tasks []*Task) {
|
32 | for _, task := range tasks {
|
33 | fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second))
|
34 | // a list of green/red pomodoros
|
35 | // green[x x] red[x x]
|
36 | fmt.Printf("[")
|
37 | for i := 0; i < task.NPomodoros; i++ {
|
38 | if i > 0 {
|
39 | fmt.Printf(" ")
|
40 | }
|
41 | if len(task.Pomodoros) >= i {
|
42 | color.New(color.FgGreen).Printf("X")
|
43 | } else {
|
44 | color.New(color.FgRed).Printf("X")
|
45 | }
|
46 | }
|
47 | fmt.Printf("]")
|
48 | if len(task.Tags) > 0 {
|
49 | fmt.Printf(" [")
|
50 | for i, tag := range task.Tags {
|
51 | if color, ok := config.Colors[tag]; ok {
|
52 | if i > 0 {
|
53 | fmt.Printf(" ")
|
54 | }
|
55 | color.Printf("%s", tag)
|
56 | }
|
57 | }
|
58 | fmt.Printf("]")
|
59 | }
|
60 | fmt.Printf(" - %s", task.Message)
|
61 | fmt.Printf("\n")
|
62 | }
|
63 | }
|