From 569a156fd0312b94196d3d770e24a6dadc133039 Mon Sep 17 00:00:00 2001 From: paperbenni Date: Tue, 31 Aug 2021 00:31:35 +0200 Subject: [PATCH] show duration of pause between intervals --- pkg/internal/runner.go | 8 ++++++++ pkg/internal/types.go | 9 +++++---- pkg/internal/ui.go | 32 +++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/pkg/internal/runner.go b/pkg/internal/runner.go index 9325c74..3476549 100644 --- a/pkg/internal/runner.go +++ b/pkg/internal/runner.go @@ -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(), } } diff --git a/pkg/internal/types.go b/pkg/internal/types.go index d52c2e6..3043a06 100644 --- a/pkg/internal/types.go +++ b/pkg/internal/types.go @@ -102,10 +102,11 @@ func (p Pomodoro) Duration() time.Duration { // Status is used to communicate the state // of a running Pomodoro session type Status struct { - State State `json:"state"` - Remaining time.Duration `json:"remaining"` - Count int `json:"count"` - NPomodoros int `json:"n_pomodoros"` + State State `json:"state"` + Remaining time.Duration `json:"remaining"` + Pauseduration time.Duration `json:"pauseduration"` + Count int `json:"count"` + NPomodoros int `json:"n_pomodoros"` } // Notifier sends a system notification diff --git a/pkg/internal/ui.go b/pkg/internal/ui.go index b5f9475..9747a4b 100644 --- a/pkg/internal/ui.go +++ b/pkg/internal/ui.go @@ -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! - [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: 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 "": runner.Toggle() + resize() render() case "p": runner.Pause() render() } case <-ticker.C: + if runner.state != laststate { + resize() + laststate = runner.state + } render() } }