Skip to content

Commit 938b9cc

Browse files
committed
feat(config): replace askToContinue with onSessionEnd for session-end behavior
1 parent a48c2af commit 938b9cc

File tree

8 files changed

+46
-40
lines changed

8 files changed

+46
-40
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ pomo looks for its config file in the following order:
132132
Example `pomo.yaml`:
133133

134134
```yaml
135-
# prompt to continue after session completion
136-
# false = exit when done
137-
askToContinue: true
135+
# Action to take after session completion
136+
# available options: (ask, skip, quit)
137+
onSessionEnd: "ask"
138138

139139
asciiArt:
140140
# use ASCII art for timer display

cmd/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func runTask(taskType config.TaskType, cmd *cobra.Command) {
2222

2323
log.Printf("starting %v session: %v", taskType.GetTask().Title, taskType.GetTask().Duration)
2424

25-
m := ui.NewModel(taskType, config.C.ASCIIArt, config.C.AskToContinue)
25+
m := ui.NewModel(taskType, config.C.ASCIIArt, config.C.OnSessionEnd)
2626
p := tea.NewProgram(m, tea.WithAltScreen())
2727

2828
finalModel, err := p.Run()

config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ type ASCIIArt struct {
4545
}
4646

4747
type Config struct {
48-
Work Task
49-
Break Task
50-
AskToContinue bool
51-
ASCIIArt ASCIIArt
48+
Work Task
49+
Break Task
50+
OnSessionEnd string
51+
ASCIIArt ASCIIArt
5252
}
5353

5454
var (
@@ -57,7 +57,7 @@ var (
5757
C Config
5858

5959
DefaultConfig = map[string]any{
60-
"askToContinue": true,
60+
"onSessionEnd": "ask",
6161
"asciiArt": map[string]any{
6262
"enabled": true,
6363
"font": ascii.DefaultFont,

config/config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestMain(m *testing.M) {
1919

2020
func TestLoadConfig(t *testing.T) {
2121
testConfig := `
22-
askToContinue: true
22+
onSessionEnd: ask
2323
work:
2424
duration: 31m
2525
title: custom work
@@ -28,7 +28,7 @@ work:
2828
setupViper()
2929
writeAndLoadConfig(t, testConfig)
3030

31-
assert.True(t, C.AskToContinue, "AskToContinue should be true")
31+
assert.Equal(t, "ask", C.OnSessionEnd, "OnSessionEnd should be 'ask'")
3232
assert.Equal(t, 31*time.Minute, C.Work.Duration, "Work duration should be 31 minutes")
3333
assert.Equal(t, "custom work", C.Work.Title, "Work title should be 'custom work'")
3434
}
@@ -46,7 +46,7 @@ func TestLoadConfigDefaults(t *testing.T) {
4646

4747
func TestLoadConfigPartialUpdate(t *testing.T) {
4848
partialConfig := `
49-
askToContinue: true
49+
onSessionEnd: ask
5050
work:
5151
duration: 30m
5252
title: custom work
@@ -58,7 +58,7 @@ asciiArt:
5858
writeAndLoadConfig(t, partialConfig)
5959

6060
// test overridden values
61-
assert.True(t, C.AskToContinue, "AskToContinue should be true")
61+
assert.Equal(t, "ask", C.OnSessionEnd, "OnSessionEnd should be 'ask'")
6262
assert.Equal(t, 30*time.Minute, C.Work.Duration, "Work duration should be 30 minutes")
6363
assert.Equal(t, "custom work", C.Work.Title, "Work title should be 'custom work'")
6464
assert.Equal(t, "#FF0000", C.ASCIIArt.Color, "ASCII art color should be '#FF0000'")
@@ -96,7 +96,7 @@ work:
9696

9797
func TestLoadConfigAllFieldsComprehensive(t *testing.T) {
9898
configYAML := `
99-
askToContinue: true
99+
onSessionEnd: ask
100100
asciiArt:
101101
enabled: true
102102
font: ansi
@@ -130,7 +130,7 @@ break:
130130
writeAndLoadConfig(t, configYAML)
131131

132132
// main config
133-
assert.True(t, C.AskToContinue, "AskToContinue should be true")
133+
assert.Equal(t, "ask", C.OnSessionEnd, "OnSessionEnd should be 'ask'")
134134

135135
// ASCII art
136136
assert.True(t, C.ASCIIArt.Enabled, "ASCII art should be enabled")
@@ -274,7 +274,7 @@ func getDefaultConfig() Config {
274274
// assertConfigMatches validates all fields between expected and actual config
275275
func assertConfigMatches(t *testing.T, expected Config, actual Config) {
276276
// main config assertion
277-
assert.Equal(t, expected.AskToContinue, actual.AskToContinue)
277+
assert.Equal(t, expected.OnSessionEnd, actual.OnSessionEnd)
278278

279279
// ASCII Art assertions
280280
assert.Equal(t, expected.ASCIIArt.Enabled, actual.ASCIIArt.Enabled)

config/schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"description": "Configuration schema for pomo - Terminal Pomodoro Timer",
66
"type": "object",
77
"properties": {
8-
"askToContinue": {
9-
"type": "boolean",
10-
"description": "Prompt to continue after completion (false = exit when done)",
11-
"default": true
8+
"onSessionEnd": {
9+
"type": "string",
10+
"description": "Action to take when session ends",
11+
"enum": ["ask", "skip", "quit"],
12+
"default": "ask"
1213
},
1314
"asciiArt": {
1415
"type": "object",

pomo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pomo config file
33
# https://github.com/Bahaaio/pomo
44

5-
askToContinue: true
5+
onSessionEnd: "ask"
66

77
asciiArt:
88
enabled: true

ui/handlers.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,24 @@ func (m *Model) handleCompletion() tea.Cmd {
145145
m.recordSession()
146146
actions.RunPostActions(&m.currentTask).Wait()
147147

148-
// show confirmation dialog if configured to do so
149-
if m.shouldAskToContinue {
148+
// continue after the completion according to config
149+
switch m.onSessionEnd {
150+
case "ask":
150151
m.sessionState = ShowingConfirm
151152
m.confirmStartTime = time.Now()
152153

153154
// send first confirm tick
154155
return func() tea.Msg {
155156
return confirmTickMsg{}
156157
}
158+
case "skip":
159+
return m.nextSession()
160+
case "quit":
161+
return m.Quit()
162+
default:
163+
log.Printf("unknown onSessionEnd value %q, defaulting to quit", m.onSessionEnd)
164+
return m.Quit()
157165
}
158-
159-
// else, quit
160-
return m.Quit()
161166
}
162167

163168
// starts session with the opposite task type (work <-> break)

ui/model.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ type Model struct {
2828
elapsed time.Duration
2929

3030
// state
31-
width, height int // window dimensions
32-
shouldAskToContinue bool
33-
sessionState SessionState
34-
confirmStartTime time.Time
35-
currentTaskType config.TaskType
36-
currentTask config.Task
37-
sessionSummary summary.SessionSummary
38-
isShortSession bool
31+
width, height int // window dimensions
32+
onSessionEnd string
33+
sessionState SessionState
34+
confirmStartTime time.Time
35+
currentTaskType config.TaskType
36+
currentTask config.Task
37+
sessionSummary summary.SessionSummary
38+
isShortSession bool
3939

4040
// ASCII art
4141
useTimerArt bool
@@ -46,7 +46,7 @@ type Model struct {
4646
repo *db.SessionRepo
4747
}
4848

49-
func NewModel(taskType config.TaskType, asciiArt config.ASCIIArt, askToContinue bool) Model {
49+
func NewModel(taskType config.TaskType, asciiArt config.ASCIIArt, onSessionEnd string) Model {
5050
task := taskType.GetTask()
5151

5252
var timerFont ascii.Font
@@ -83,11 +83,11 @@ func NewModel(taskType config.TaskType, asciiArt config.ASCIIArt, askToContinue
8383
timer: timer.New(task.Duration),
8484
duration: task.Duration,
8585

86-
shouldAskToContinue: askToContinue,
87-
sessionState: Running,
88-
currentTaskType: taskType,
89-
currentTask: *task,
90-
sessionSummary: sessionSummary,
86+
onSessionEnd: onSessionEnd,
87+
sessionState: Running,
88+
currentTaskType: taskType,
89+
currentTask: *task,
90+
sessionSummary: sessionSummary,
9191

9292
useTimerArt: asciiArt.Enabled,
9393
timerFont: timerFont,

0 commit comments

Comments
 (0)