Commit
+24 -4 +/-3 browse
1 | diff --git a/main.go b/main.go |
2 | index a3fcce6..402024a 100644 |
3 | --- a/main.go |
4 | +++ b/main.go |
5 | @@ -74,7 +74,8 @@ func list(path *string) func(*cli.Cmd) { |
6 | maybe(json.NewEncoder(os.Stdout).Encode(tasks)) |
7 | return |
8 | } |
9 | - config, _ := NewConfig(*path + "/config.json") |
10 | + config, err := NewConfig(*path + "/config.json") |
11 | + maybe(err) |
12 | summerizeTasks(config, tasks) |
13 | } |
14 | } |
15 | diff --git a/types.go b/types.go |
16 | index a6d03ca..ad2d072 100644 |
17 | --- a/types.go |
18 | +++ b/types.go |
19 | @@ -11,6 +11,10 @@ import ( |
20 | "github.com/fatih/color" |
21 | ) |
22 | |
23 | + const ( |
24 | + defaultDateTimeFmt = "2006-01-02 15:04" |
25 | + ) |
26 | + |
27 | type State int |
28 | |
29 | func (s State) String() string { |
30 | @@ -57,7 +61,8 @@ func (w *Wheel) String() string { |
31 | |
32 | // Config represents user preferences |
33 | type Config struct { |
34 | - Colors map[string]*color.Color |
35 | + Colors map[string]*color.Color |
36 | + DateTimeFmt string |
37 | } |
38 | |
39 | var colorMap = map[string]*color.Color{ |
40 | @@ -69,7 +74,8 @@ var colorMap = map[string]*color.Color{ |
41 | |
42 | func (c *Config) UnmarshalJSON(raw []byte) error { |
43 | config := &struct { |
44 | - Colors map[string]string `json:"colors"` |
45 | + Colors map[string]string `json:"colors"` |
46 | + DateTimeFmt string `json:"datetimefmt"` |
47 | }{} |
48 | err := json.Unmarshal(raw, config) |
49 | if err != nil { |
50 | @@ -82,6 +88,11 @@ func (c *Config) UnmarshalJSON(raw []byte) error { |
51 | return fmt.Errorf("bad color choice: %s", name) |
52 | } |
53 | } |
54 | + if config.DateTimeFmt != "" { |
55 | + c.DateTimeFmt = config.DateTimeFmt |
56 | + } else { |
57 | + c.DateTimeFmt = defaultDateTimeFmt |
58 | + } |
59 | return nil |
60 | } |
61 | |
62 | @@ -100,6 +111,10 @@ func NewConfig(path string) (*Config, error) { |
63 | config := &Config{ |
64 | Colors: map[string]*color.Color{}, |
65 | } |
66 | + err = json.Unmarshal(raw, config) |
67 | + if err != nil { |
68 | + return nil, err |
69 | + } |
70 | return config, json.Unmarshal(raw, config) |
71 | } |
72 | |
73 | diff --git a/util.go b/util.go |
74 | index a98185d..a2de6ec 100644 |
75 | --- a/util.go |
76 | +++ b/util.go |
77 | @@ -23,7 +23,11 @@ func defaultConfigPath() string { |
78 | |
79 | func summerizeTasks(config *Config, tasks []*Task) { |
80 | for _, task := range tasks { |
81 | - fmt.Printf("%d: [%s] ", task.ID, task.Duration.Truncate(time.Second)) |
82 | + var start string |
83 | + if len(task.Pomodoros) > 0 { |
84 | + start = task.Pomodoros[0].Start.Format(config.DateTimeFmt) |
85 | + } |
86 | + fmt.Printf("%d: [%s] [%s] ", task.ID, start, task.Duration.Truncate(time.Second)) |
87 | // a list of green/yellow/red pomodoros |
88 | // green indicates the pomodoro was finished normally |
89 | // yellow indicates the break was exceeded by +5minutes |