improve output, encode duration + target pomodoros

master
Kevin Schoon 6 years ago
parent b5042fdbeb
commit cb5779343f

@ -24,10 +24,10 @@ func start(path *string) func(*cli.Cmd) {
maybe(err)
defer db.Close()
task := Task{
Message: *message,
Tags: *tags,
pomodoros: *pomodoros,
duration: parsed,
Message: *message,
Tags: *tags,
NPomodoros: *pomodoros,
Duration: parsed,
}
run(task, &I3{}, db)
}

@ -30,7 +30,9 @@ func (s Store) CreateTask(task Task) (int, error) {
if err != nil {
return -1, err
}
_, err = tx.Exec("INSERT INTO task (message,tags) VALUES ($1,$2)", task.Message, strings.Join(task.Tags, ","))
_, err = tx.Exec(
"INSERT INTO task (message,pomodoros,duration,tags) VALUES ($1,$2,$3,$4)",
task.Message, task.NPomodoros, task.Duration.String(), strings.Join(task.Tags, ","))
if err != nil {
tx.Rollback()
return -1, err
@ -54,18 +56,23 @@ func (s Store) CreatePomodoro(taskID int, pomodoro Pomodoro) error {
}
func (s Store) ReadTasks() ([]*Task, error) {
rows, err := s.db.Query(`SELECT rowid,message,tags FROM task`)
rows, err := s.db.Query(`SELECT rowid,message,pomodoros,duration,tags FROM task`)
if err != nil {
return nil, err
}
tasks := []*Task{}
for rows.Next() {
var tags string
var (
tags string
strDuration string
)
task := &Task{Pomodoros: []*Pomodoro{}}
err = rows.Scan(&task.ID, &task.Message, &tags)
err = rows.Scan(&task.ID, &task.Message, &task.NPomodoros, &strDuration, &tags)
if err != nil {
return nil, err
}
duration, _ := time.ParseDuration(strDuration)
task.Duration = duration
if tags != "" {
task.Tags = strings.Split(tags, ",")
}
@ -130,6 +137,8 @@ func initDB(db *Store) error {
stmt := `
CREATE TABLE task (
message TEXT,
pomodoros INTEGER,
duration TEXT,
tags TEXT
);
CREATE TABLE pomodoro (

@ -31,21 +31,21 @@ func run(task Task, prompter Prompter, db *Store) {
writer := uilive.New()
writer.Start()
ticker := time.NewTicker(RefreshInterval)
timer := time.NewTimer(task.duration)
timer := time.NewTimer(task.Duration)
wheel := &Wheel{}
var p int
for p < task.pomodoros {
for p < task.NPomodoros {
pomodoro := &Pomodoro{}
maybe(prompter.Prompt("Begin working!"))
pomodoro.Start = time.Now()
timer.Reset(task.duration)
timer.Reset(task.Duration)
loop:
select {
case <-ticker.C:
display(writer, Message{
Start: pomodoro.Start,
Duration: task.duration,
Pomodoros: task.pomodoros,
Duration: task.Duration,
Pomodoros: task.NPomodoros,
Wheel: wheel,
CurrentPomodoro: p,
})

@ -89,14 +89,16 @@ func NewConfig(path string) (*Config, error) {
// Task describes some activity
type Task struct {
ID int `json:"id"`
Message string `json:"message"`
ID int `json:"id"`
Message string `json:"message"`
// Array of completed pomodoros
Pomodoros []*Pomodoro `json:"pomodoros"`
// Free-form tags associated with this task
Tags []string `json:"tags"`
// Number of pomodoros for this task
pomodoros int
duration time.Duration
NPomodoros int `json:"n_pomodoros"`
// Duration of each pomodoro
Duration time.Duration `json:"duration"`
}
// ByID is a sortable array of tasks

@ -2,9 +2,10 @@ package main
import (
"fmt"
//"github.com/fatih/color"
"github.com/fatih/color"
"os"
"os/user"
"time"
)
func maybe(err error) {
@ -22,17 +23,34 @@ func defaultConfigPath() string {
func summerizeTasks(config *Config, tasks []*Task) {
for _, task := range tasks {
var tags string
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("]")
if len(task.Tags) > 0 {
fmt.Printf(" [")
for i, tag := range task.Tags {
if color, ok := config.Colors[tag]; ok {
if i > 0 {
tags += " "
fmt.Printf(" ")
}
tags += color.SprintfFunc()("%s", tag)
color.Printf("%s", tag)
}
}
fmt.Printf("]")
}
fmt.Printf("%d [%s]: %s\n", task.ID, tags, task.Message)
fmt.Printf(" - %s", task.Message)
fmt.Printf("\n")
}
}

Loading…
Cancel
Save