Commit
+40 -9 +/-3 browse
1 | diff --git a/pkg/internal/runner.go b/pkg/internal/runner.go |
2 | index 9325c74..3476549 100644 |
3 | --- a/pkg/internal/runner.go |
4 | +++ b/pkg/internal/runner.go |
5 | @@ -14,6 +14,7 @@ type TaskRunner struct { |
6 | state State |
7 | store *Store |
8 | started time.Time |
9 | + stopped time.Time |
10 | pause chan bool |
11 | toggle chan bool |
12 | notifier Notifier |
13 | @@ -63,6 +64,10 @@ func (t *TaskRunner) TimeRemaining() time.Duration { |
14 | return (t.duration - time.Since(t.started)).Truncate(time.Second) |
15 | } |
16 | |
17 | + func (t *TaskRunner) TimePauseDuration() time.Duration { |
18 | + return (time.Since(t.stopped)).Truncate(time.Second) |
19 | + } |
20 | + |
21 | func (t *TaskRunner) SetState(state State) { |
22 | t.state = state |
23 | } |
24 | @@ -85,6 +90,7 @@ func (t *TaskRunner) run() error { |
25 | select { |
26 | case <-timer.C: |
27 | t.SetState(BREAKING) |
28 | + t.stopped = time.Now() |
29 | t.count++ |
30 | case <-t.toggle: |
31 | // Catch any toggles when we |
32 | @@ -120,6 +126,7 @@ func (t *TaskRunner) run() error { |
33 | break |
34 | } |
35 | |
36 | + |
37 | t.notifier.Notify("Pomo", "It is time to take a break!") |
38 | // Reset the duration incase it |
39 | // was paused. |
40 | @@ -147,5 +154,6 @@ func (t *TaskRunner) Status() *Status { |
41 | Count: t.count, |
42 | NPomodoros: t.nPomodoros, |
43 | Remaining: t.TimeRemaining(), |
44 | + Pauseduration: t.TimePauseDuration(), |
45 | } |
46 | } |
47 | diff --git a/pkg/internal/types.go b/pkg/internal/types.go |
48 | index d52c2e6..3043a06 100644 |
49 | --- a/pkg/internal/types.go |
50 | +++ b/pkg/internal/types.go |
51 | @@ -102,10 +102,11 @@ func (p Pomodoro) Duration() time.Duration { |
52 | // Status is used to communicate the state |
53 | // of a running Pomodoro session |
54 | type Status struct { |
55 | - State State `json:"state"` |
56 | - Remaining time.Duration `json:"remaining"` |
57 | - Count int `json:"count"` |
58 | - NPomodoros int `json:"n_pomodoros"` |
59 | + State State `json:"state"` |
60 | + Remaining time.Duration `json:"remaining"` |
61 | + Pauseduration time.Duration `json:"pauseduration"` |
62 | + Count int `json:"count"` |
63 | + NPomodoros int `json:"n_pomodoros"` |
64 | } |
65 | |
66 | // Notifier sends a system notification |
67 | diff --git a/pkg/internal/ui.go b/pkg/internal/ui.go |
68 | index b5f9475..9747a4b 100644 |
69 | --- a/pkg/internal/ui.go |
70 | +++ b/pkg/internal/ui.go |
71 | @@ -25,13 +25,22 @@ func setContent(wheel *Wheel, status *Status, par *widgets.Paragraph) { |
72 | status.Remaining, |
73 | ) |
74 | case BREAKING: |
75 | - par.Text = `It is time to take a break! |
76 | |
77 | - Once you are ready, press [enter] |
78 | - to begin the next Pomodoro. |
79 | + par.Text = fmt.Sprintf( |
80 | + `It is time to take a break! |
81 | |
82 | - [q] - quit [p] - pause |
83 | - ` |
84 | + |
85 | + Once you are ready, press [Enter] |
86 | + to begin the next Pomodoro |
87 | + |
88 | + %s %s pause duration |
89 | + |
90 | + |
91 | + [q] - quit [p] - pause |
92 | + `, |
93 | + wheel, |
94 | + status.Pauseduration, |
95 | + ) |
96 | case PAUSED: |
97 | par.Text = `Pomo is suspended. |
98 | |
99 | @@ -76,9 +85,16 @@ func StartUI(runner *TaskRunner) { |
100 | |
101 | x1 := (termWidth - 50) / 2 |
102 | x2 := x1 + 50 |
103 | + |
104 | y1 := (termHeight - 8) / 2 |
105 | y2 := y1 + 8 |
106 | |
107 | + switch runner.state { |
108 | + case BREAKING: |
109 | + y1 = (termHeight - 12) / 2 |
110 | + y2 = y1 + 12 |
111 | + } |
112 | + |
113 | par.SetRect(x1, y1, x2, y2) |
114 | ui.Clear() |
115 | } |
116 | @@ -94,6 +110,7 @@ func StartUI(runner *TaskRunner) { |
117 | events := ui.PollEvents() |
118 | |
119 | for { |
120 | + laststate := runner.state |
121 | select { |
122 | case e := <-events: |
123 | switch e.ID { |
124 | @@ -104,12 +121,17 @@ func StartUI(runner *TaskRunner) { |
125 | render() |
126 | case "<Enter>": |
127 | runner.Toggle() |
128 | + resize() |
129 | render() |
130 | case "p": |
131 | runner.Pause() |
132 | render() |
133 | } |
134 | case <-ticker.C: |
135 | + if runner.state != laststate { |
136 | + resize() |
137 | + laststate = runner.state |
138 | + } |
139 | render() |
140 | } |
141 | } |