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
|
/* beefsteak: a pomodoro timer */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define WORK_TIME_MIN 50
#define BREAK_TIME_MIN 10
#define SESSION_COUNT 3
/* System requirements:
* notify-send
* */
/* 60 SECONDS = 1 MINUTE */
/* 60 MINUTES = 1 HOUR, 3600 SECONDS */
int work_time_seconds = WORK_TIME_MIN * 60;
int break_time_seconds = BREAK_TIME_MIN * 60;
int clear_stream(void) {
fflush(stdout);
printf("\r");
return(0);
}
void seconds_to_string(int seconds) {
int hour = 0;
int minute = 0;
if ((seconds/60) >= 60) { // If seconds > one hour
hour = (seconds - (seconds % 3600)) / 3600;
seconds = seconds % 600;
}
if ((seconds/60) >= 1) { // If seconds > one minute
minute = (seconds - (seconds % 60)) / 60;
seconds = seconds % 60;
}
printf("%.2d:%.2d:%.2d", hour, minute, seconds);
/* FOR FIGLET IN THE FUTURE: */
/* char timer[10];
sprintf(timer, "%.2d:%.2d:%.2d", hour, minute, seconds);
printf("%s", timer); */
clear_stream();
}
int send_notification(int type) {
char command[100], message[100];
strcpy(command, "notify-send "); /* Notifcation Backend */
switch(type) {
case 0: /* Work Started */
sprintf(message, "\"🍅 Work Session Started\" \"Time Remaining: %d minutes.\"", WORK_TIME_MIN);
strcat(command, message);
system(command);
break;
case 1: /* Break Started */
sprintf(message, "\"🏖️ Break Session Started\" \"Time Remaining: %d minutes.\"", BREAK_TIME_MIN);
strcat(command, message);
system(command);
break;
case 2: /* Session Ended*/
sprintf(message, "\"🕰️ Pomodoro Session Started\" \"All Done.\"");
strcat(command, message);
system(command);
break;
}
return 0;
}
int main(int argc, char **argv) {
for (int i = 0; i < SESSION_COUNT; i++) {
send_notification(0);
while (work_time_seconds > 0) {
printf("Work Time Left: ");
seconds_to_string(work_time_seconds);
sleep(1);
work_time_seconds--;
}
send_notification(1);
while (break_time_seconds > 0) {
printf("Break Time Left: ");
seconds_to_string(break_time_seconds);
sleep(1);
break_time_seconds--;
}
}
send_notification(2);
return 0;
}
|