Merge pull request #45 from paperbenni/master
[Feature] show duration of pause between intervals
This commit is contained in:
commit
1ad3c18c8a
|
@ -14,6 +14,7 @@ type TaskRunner struct {
|
|||
state State
|
||||
store *Store
|
||||
started time.Time
|
||||
stopped time.Time
|
||||
pause chan bool
|
||||
toggle chan bool
|
||||
notifier Notifier
|
||||
|
@ -63,6 +64,10 @@ func (t *TaskRunner) TimeRemaining() time.Duration {
|
|||
return (t.duration - time.Since(t.started)).Truncate(time.Second)
|
||||
}
|
||||
|
||||
func (t *TaskRunner) TimePauseDuration() time.Duration {
|
||||
return (time.Since(t.stopped)).Truncate(time.Second)
|
||||
}
|
||||
|
||||
func (t *TaskRunner) SetState(state State) {
|
||||
t.state = state
|
||||
}
|
||||
|
@ -85,6 +90,7 @@ func (t *TaskRunner) run() error {
|
|||
select {
|
||||
case <-timer.C:
|
||||
t.SetState(BREAKING)
|
||||
t.stopped = time.Now()
|
||||
t.count++
|
||||
case <-t.toggle:
|
||||
// Catch any toggles when we
|
||||
|
@ -120,6 +126,7 @@ func (t *TaskRunner) run() error {
|
|||
break
|
||||
}
|
||||
|
||||
|
||||
t.notifier.Notify("Pomo", "It is time to take a break!")
|
||||
// Reset the duration incase it
|
||||
// was paused.
|
||||
|
@ -147,5 +154,6 @@ func (t *TaskRunner) Status() *Status {
|
|||
Count: t.count,
|
||||
NPomodoros: t.nPomodoros,
|
||||
Remaining: t.TimeRemaining(),
|
||||
Pauseduration: t.TimePauseDuration(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ func (p Pomodoro) Duration() time.Duration {
|
|||
type Status struct {
|
||||
State State `json:"state"`
|
||||
Remaining time.Duration `json:"remaining"`
|
||||
Pauseduration time.Duration `json:"pauseduration"`
|
||||
Count int `json:"count"`
|
||||
NPomodoros int `json:"n_pomodoros"`
|
||||
}
|
||||
|
|
|
@ -25,13 +25,22 @@ func setContent(wheel *Wheel, status *Status, par *widgets.Paragraph) {
|
|||
status.Remaining,
|
||||
)
|
||||
case BREAKING:
|
||||
par.Text = `It is time to take a break!
|
||||
|
||||
Once you are ready, press [enter]
|
||||
to begin the next Pomodoro.
|
||||
par.Text = fmt.Sprintf(
|
||||
`It is time to take a break!
|
||||
|
||||
|
||||
Once you are ready, press [Enter]
|
||||
to begin the next Pomodoro
|
||||
|
||||
%s %s pause duration
|
||||
|
||||
|
||||
[q] - quit [p] - pause
|
||||
`
|
||||
`,
|
||||
wheel,
|
||||
status.Pauseduration,
|
||||
)
|
||||
case PAUSED:
|
||||
par.Text = `Pomo is suspended.
|
||||
|
||||
|
@ -76,9 +85,16 @@ func StartUI(runner *TaskRunner) {
|
|||
|
||||
x1 := (termWidth - 50) / 2
|
||||
x2 := x1 + 50
|
||||
|
||||
y1 := (termHeight - 8) / 2
|
||||
y2 := y1 + 8
|
||||
|
||||
switch runner.state {
|
||||
case BREAKING:
|
||||
y1 = (termHeight - 12) / 2
|
||||
y2 = y1 + 12
|
||||
}
|
||||
|
||||
par.SetRect(x1, y1, x2, y2)
|
||||
ui.Clear()
|
||||
}
|
||||
|
@ -94,6 +110,7 @@ func StartUI(runner *TaskRunner) {
|
|||
events := ui.PollEvents()
|
||||
|
||||
for {
|
||||
laststate := runner.state
|
||||
select {
|
||||
case e := <-events:
|
||||
switch e.ID {
|
||||
|
@ -104,12 +121,17 @@ func StartUI(runner *TaskRunner) {
|
|||
render()
|
||||
case "<Enter>":
|
||||
runner.Toggle()
|
||||
resize()
|
||||
render()
|
||||
case "p":
|
||||
runner.Pause()
|
||||
render()
|
||||
}
|
||||
case <-ticker.C:
|
||||
if runner.state != laststate {
|
||||
resize()
|
||||
laststate = runner.state
|
||||
}
|
||||
render()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue