Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: cb5779343fc0280aa278beb72ebd4a3375a9c26f
Timestamp: Sat, 20 Jan 2018 18:54:30 +0000 (7 years ago)

+51 -22 +/-5 browse
improve output, encode duration + target pomodoros
1diff --git a/main.go b/main.go
2index 48c1ea9..0b2cd8c 100644
3--- a/main.go
4+++ b/main.go
5 @@ -24,10 +24,10 @@ func start(path *string) func(*cli.Cmd) {
6 maybe(err)
7 defer db.Close()
8 task := Task{
9- Message: *message,
10- Tags: *tags,
11- pomodoros: *pomodoros,
12- duration: parsed,
13+ Message: *message,
14+ Tags: *tags,
15+ NPomodoros: *pomodoros,
16+ Duration: parsed,
17 }
18 run(task, &I3{}, db)
19 }
20 diff --git a/store.go b/store.go
21index ac36440..f6b601b 100644
22--- a/store.go
23+++ b/store.go
24 @@ -30,7 +30,9 @@ func (s Store) CreateTask(task Task) (int, error) {
25 if err != nil {
26 return -1, err
27 }
28- _, err = tx.Exec("INSERT INTO task (message,tags) VALUES ($1,$2)", task.Message, strings.Join(task.Tags, ","))
29+ _, err = tx.Exec(
30+ "INSERT INTO task (message,pomodoros,duration,tags) VALUES ($1,$2,$3,$4)",
31+ task.Message, task.NPomodoros, task.Duration.String(), strings.Join(task.Tags, ","))
32 if err != nil {
33 tx.Rollback()
34 return -1, err
35 @@ -54,18 +56,23 @@ func (s Store) CreatePomodoro(taskID int, pomodoro Pomodoro) error {
36 }
37
38 func (s Store) ReadTasks() ([]*Task, error) {
39- rows, err := s.db.Query(`SELECT rowid,message,tags FROM task`)
40+ rows, err := s.db.Query(`SELECT rowid,message,pomodoros,duration,tags FROM task`)
41 if err != nil {
42 return nil, err
43 }
44 tasks := []*Task{}
45 for rows.Next() {
46- var tags string
47+ var (
48+ tags string
49+ strDuration string
50+ )
51 task := &Task{Pomodoros: []*Pomodoro{}}
52- err = rows.Scan(&task.ID, &task.Message, &tags)
53+ err = rows.Scan(&task.ID, &task.Message, &task.NPomodoros, &strDuration, &tags)
54 if err != nil {
55 return nil, err
56 }
57+ duration, _ := time.ParseDuration(strDuration)
58+ task.Duration = duration
59 if tags != "" {
60 task.Tags = strings.Split(tags, ",")
61 }
62 @@ -130,6 +137,8 @@ func initDB(db *Store) error {
63 stmt := `
64 CREATE TABLE task (
65 message TEXT,
66+ pomodoros INTEGER,
67+ duration TEXT,
68 tags TEXT
69 );
70 CREATE TABLE pomodoro (
71 diff --git a/task.go b/task.go
72index 1e93324..685717c 100644
73--- a/task.go
74+++ b/task.go
75 @@ -31,21 +31,21 @@ func run(task Task, prompter Prompter, db *Store) {
76 writer := uilive.New()
77 writer.Start()
78 ticker := time.NewTicker(RefreshInterval)
79- timer := time.NewTimer(task.duration)
80+ timer := time.NewTimer(task.Duration)
81 wheel := &Wheel{}
82 var p int
83- for p < task.pomodoros {
84+ for p < task.NPomodoros {
85 pomodoro := &Pomodoro{}
86 maybe(prompter.Prompt("Begin working!"))
87 pomodoro.Start = time.Now()
88- timer.Reset(task.duration)
89+ timer.Reset(task.Duration)
90 loop:
91 select {
92 case <-ticker.C:
93 display(writer, Message{
94 Start: pomodoro.Start,
95- Duration: task.duration,
96- Pomodoros: task.pomodoros,
97+ Duration: task.Duration,
98+ Pomodoros: task.NPomodoros,
99 Wheel: wheel,
100 CurrentPomodoro: p,
101 })
102 diff --git a/types.go b/types.go
103index 5a30678..60c2961 100644
104--- a/types.go
105+++ b/types.go
106 @@ -89,14 +89,16 @@ func NewConfig(path string) (*Config, error) {
107
108 // Task describes some activity
109 type Task struct {
110- ID int `json:"id"`
111- Message string `json:"message"`
112+ ID int `json:"id"`
113+ Message string `json:"message"`
114+ // Array of completed pomodoros
115 Pomodoros []*Pomodoro `json:"pomodoros"`
116 // Free-form tags associated with this task
117 Tags []string `json:"tags"`
118 // Number of pomodoros for this task
119- pomodoros int
120- duration time.Duration
121+ NPomodoros int `json:"n_pomodoros"`
122+ // Duration of each pomodoro
123+ Duration time.Duration `json:"duration"`
124 }
125
126 // ByID is a sortable array of tasks
127 diff --git a/util.go b/util.go
128index d710648..99aa249 100644
129--- a/util.go
130+++ b/util.go
131 @@ -2,9 +2,10 @@ package main
132
133 import (
134 "fmt"
135- //"github.com/fatih/color"
136+ "github.com/fatih/color"
137 "os"
138 "os/user"
139+ "time"
140 )
141
142 func maybe(err error) {
143 @@ -22,17 +23,34 @@ func defaultConfigPath() string {
144
145 func summerizeTasks(config *Config, tasks []*Task) {
146 for _, task := range tasks {
147- var tags string
148+ fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second))
149+ // a list of green/red pomodoros
150+ // green[x x] red[x x]
151+ fmt.Printf("[")
152+ for i := 0; i < task.NPomodoros; i++ {
153+ if i > 0 {
154+ fmt.Printf(" ")
155+ }
156+ if len(task.Pomodoros) >= i {
157+ color.New(color.FgGreen).Printf("X")
158+ } else {
159+ color.New(color.FgRed).Printf("X")
160+ }
161+ }
162+ fmt.Printf("]")
163 if len(task.Tags) > 0 {
164+ fmt.Printf(" [")
165 for i, tag := range task.Tags {
166 if color, ok := config.Colors[tag]; ok {
167 if i > 0 {
168- tags += " "
169+ fmt.Printf(" ")
170 }
171- tags += color.SprintfFunc()("%s", tag)
172+ color.Printf("%s", tag)
173 }
174 }
175+ fmt.Printf("]")
176 }
177- fmt.Printf("%d [%s]: %s\n", task.ID, tags, task.Message)
178+ fmt.Printf(" - %s", task.Message)
179+ fmt.Printf("\n")
180 }
181 }