improve output, encode duration + target pomodoros
This commit is contained in:
parent
b5042fdbeb
commit
cb5779343f
4
main.go
4
main.go
|
@ -26,8 +26,8 @@ func start(path *string) func(*cli.Cmd) {
|
||||||
task := Task{
|
task := Task{
|
||||||
Message: *message,
|
Message: *message,
|
||||||
Tags: *tags,
|
Tags: *tags,
|
||||||
pomodoros: *pomodoros,
|
NPomodoros: *pomodoros,
|
||||||
duration: parsed,
|
Duration: parsed,
|
||||||
}
|
}
|
||||||
run(task, &I3{}, db)
|
run(task, &I3{}, db)
|
||||||
}
|
}
|
||||||
|
|
17
store.go
17
store.go
|
@ -30,7 +30,9 @@ func (s Store) CreateTask(task Task) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
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 {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return -1, err
|
return -1, err
|
||||||
|
@ -54,18 +56,23 @@ func (s Store) CreatePomodoro(taskID int, pomodoro Pomodoro) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Store) ReadTasks() ([]*Task, 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tasks := []*Task{}
|
tasks := []*Task{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var tags string
|
var (
|
||||||
|
tags string
|
||||||
|
strDuration string
|
||||||
|
)
|
||||||
task := &Task{Pomodoros: []*Pomodoro{}}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
duration, _ := time.ParseDuration(strDuration)
|
||||||
|
task.Duration = duration
|
||||||
if tags != "" {
|
if tags != "" {
|
||||||
task.Tags = strings.Split(tags, ",")
|
task.Tags = strings.Split(tags, ",")
|
||||||
}
|
}
|
||||||
|
@ -130,6 +137,8 @@ func initDB(db *Store) error {
|
||||||
stmt := `
|
stmt := `
|
||||||
CREATE TABLE task (
|
CREATE TABLE task (
|
||||||
message TEXT,
|
message TEXT,
|
||||||
|
pomodoros INTEGER,
|
||||||
|
duration TEXT,
|
||||||
tags TEXT
|
tags TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE pomodoro (
|
CREATE TABLE pomodoro (
|
||||||
|
|
10
task.go
10
task.go
|
@ -31,21 +31,21 @@ func run(task Task, prompter Prompter, db *Store) {
|
||||||
writer := uilive.New()
|
writer := uilive.New()
|
||||||
writer.Start()
|
writer.Start()
|
||||||
ticker := time.NewTicker(RefreshInterval)
|
ticker := time.NewTicker(RefreshInterval)
|
||||||
timer := time.NewTimer(task.duration)
|
timer := time.NewTimer(task.Duration)
|
||||||
wheel := &Wheel{}
|
wheel := &Wheel{}
|
||||||
var p int
|
var p int
|
||||||
for p < task.pomodoros {
|
for p < task.NPomodoros {
|
||||||
pomodoro := &Pomodoro{}
|
pomodoro := &Pomodoro{}
|
||||||
maybe(prompter.Prompt("Begin working!"))
|
maybe(prompter.Prompt("Begin working!"))
|
||||||
pomodoro.Start = time.Now()
|
pomodoro.Start = time.Now()
|
||||||
timer.Reset(task.duration)
|
timer.Reset(task.Duration)
|
||||||
loop:
|
loop:
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
display(writer, Message{
|
display(writer, Message{
|
||||||
Start: pomodoro.Start,
|
Start: pomodoro.Start,
|
||||||
Duration: task.duration,
|
Duration: task.Duration,
|
||||||
Pomodoros: task.pomodoros,
|
Pomodoros: task.NPomodoros,
|
||||||
Wheel: wheel,
|
Wheel: wheel,
|
||||||
CurrentPomodoro: p,
|
CurrentPomodoro: p,
|
||||||
})
|
})
|
||||||
|
|
6
types.go
6
types.go
|
@ -91,12 +91,14 @@ func NewConfig(path string) (*Config, error) {
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
// Array of completed pomodoros
|
||||||
Pomodoros []*Pomodoro `json:"pomodoros"`
|
Pomodoros []*Pomodoro `json:"pomodoros"`
|
||||||
// Free-form tags associated with this task
|
// Free-form tags associated with this task
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
// Number of pomodoros for this task
|
// Number of pomodoros for this task
|
||||||
pomodoros int
|
NPomodoros int `json:"n_pomodoros"`
|
||||||
duration time.Duration
|
// Duration of each pomodoro
|
||||||
|
Duration time.Duration `json:"duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByID is a sortable array of tasks
|
// ByID is a sortable array of tasks
|
||||||
|
|
28
util.go
28
util.go
|
@ -2,9 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
//"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func maybe(err error) {
|
func maybe(err error) {
|
||||||
|
@ -22,17 +23,34 @@ func defaultConfigPath() string {
|
||||||
|
|
||||||
func summerizeTasks(config *Config, tasks []*Task) {
|
func summerizeTasks(config *Config, tasks []*Task) {
|
||||||
for _, task := range tasks {
|
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 {
|
if len(task.Tags) > 0 {
|
||||||
|
fmt.Printf(" [")
|
||||||
for i, tag := range task.Tags {
|
for i, tag := range task.Tags {
|
||||||
if color, ok := config.Colors[tag]; ok {
|
if color, ok := config.Colors[tag]; ok {
|
||||||
if i > 0 {
|
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…
Reference in New Issue