-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomodoro.go
More file actions
135 lines (110 loc) · 2.65 KB
/
pomodoro.go
File metadata and controls
135 lines (110 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
"os/exec"
"time"
)
// func pomodoroTurn(c chan string) {
// turn := 1
// time.Sleep(time.Second * 10)
// c <- "One pomodoro turn done!"
// turn++
// }
// func shortBreak(c chan string) {
// time.Sleep(time.Second * 5)
// c <- "Short break has ended!"
// }
// func main() {
// chan1 := make(chan string)
// fmt.Println("\x1b[32;1mYou've launched the Pomodoro!\x1b[0m")
// go pomodoroTurn(chan1)
// go shortBreak(chan1)
// msg := <-chan1
// fmt.Println(msg)
// }
var (
currentTurn = 1
totalTurns = 3
)
func main() {
turn := make(chan bool)
smallBreak := make(chan bool)
longBreak := make(chan bool)
done := make(chan bool)
go pomodoroTurn(turn)
go pomodoroService(turn, smallBreak, longBreak, done)
<-done
}
func pomodoroTurn(chanPomodoro chan bool) {
tellBeginTurn()
// time.Sleep(time.Minute * 25)
time.Sleep(time.Second * 5)
tellEndTurn()
chanPomodoro <- true
}
func pomodoroBreak(chanBreak chan bool) {
tellBeginSmallBreak()
time.Sleep(time.Second * 5)
tellEndSmallBreak()
chanBreak <- true
}
func pomodoroLongBreak(chanLongBreak chan bool) {
tellBeginLongBreak()
time.Sleep(time.Second * 5)
tellEndLongBreak()
chanLongBreak <- true
}
func tellBeginTurn() {
exec.Command("say", "Pomodoro round begins").Output()
}
func tellEndTurn() {
exec.Command("say", "Round ended").Output()
}
func tellBeginSmallBreak() {
exec.Command("say", "Have a small break!").Output()
}
func tellEndSmallBreak() {
exec.Command("say", "This is the end of the small break. Let's go back to work!").Output()
}
func tellBeginLongBreak() {
exec.Command("say", "Have a long break! You deserve it!").Output()
}
func tellEndLongBreak() {
exec.Command("say", "This is the end of the long break. Let's go back to work!").Output()
}
func pomodoroService(chanPomodoro, chanBreak, chanLongBreak, chanDone chan bool) {
fmt.Println("Pomodoro service started\n")
for {
select {
case endTurn := <-chanPomodoro:
_ = endTurn
if currentTurn >= totalTurns {
go pomodoroLongBreak(chanLongBreak)
currentTurn = 1
} else {
currentTurn += 1
go pomodoroBreak(chanBreak)
}
case endSmallBreak := <-chanBreak:
_ = endSmallBreak
go pomodoroTurn(chanPomodoro)
case endLongBreak := <-chanLongBreak:
_ = endLongBreak
input := askAnotherSession()
for input != "Y" && input != "N" && input != "y" && input != "n" {
input = askAnotherSession()
}
if input == "Y" || input == "y" {
go pomodoroTurn(chanPomodoro)
} else {
chanDone <- true
}
}
}
}
func askAnotherSession() string {
fmt.Println("Ready for another pomodoro session? (Y/N)")
var input string
fmt.Scanln(&input)
return input
}