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