blob: b8e69147686bdc268f160a7ea7ed7700516937c5 (
plain) (
blame)
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
|
package main
import (
"fmt"
"time"
)
type state int
const (
Working state = iota
Break
LongBreak
)
var (
currentState = Working
currentDuration = 25 * 60
pomodoros = 1
)
func main() {
for {
clearline()
switch currentState {
case Working:
fmt.Printf("🍅 #%d Working (%s)", pomodoros, secondsToMinutes(currentDuration))
case Break:
fmt.Printf("☕️ #%d Break (%s)", pomodoros, secondsToMinutes(currentDuration))
case LongBreak:
fmt.Printf("☕️ #%d Long break (%s)", pomodoros, secondsToMinutes(currentDuration))
}
currentDuration--
if currentDuration < 0 {
switch currentState {
case Working:
if pomodoros%4 == 0 {
currentState = LongBreak
currentDuration = 15 * 60
} else {
currentState = Break
currentDuration = 5 * 60
}
case Break, LongBreak:
currentState = Working
currentDuration = 25 * 60
pomodoros++
}
bell()
}
<-time.After(1 * time.Second)
}
}
func bell() {
fmt.Print("\a")
}
func clearline() {
fmt.Print("\x1b[2K\r")
}
func secondsToMinutes(inSeconds int) string {
minutes := inSeconds / 60
seconds := inSeconds % 60
str := fmt.Sprintf("%02d:%02d", minutes, seconds)
return str
}
|