Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] show duration of pause between intervals #45

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/internal/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -147,5 +154,6 @@ func (t *TaskRunner) Status() *Status {
Count: t.count,
NPomodoros: t.nPomodoros,
Remaining: t.TimeRemaining(),
Pauseduration: t.TimePauseDuration(),
}
}
9 changes: 5 additions & 4 deletions pkg/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions pkg/internal/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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()
}
Expand All @@ -94,6 +110,7 @@ func StartUI(runner *TaskRunner) {
events := ui.PollEvents()

for {
laststate := runner.state
select {
case e := <-events:
switch e.ID {
Expand All @@ -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()
}
}
Expand Down