/* beefsteak: a pomodoro timer */ #include #include #include #include #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 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 Complete\" \"All Done.\""); strcat(command, message); system(command); break; } return 0; } int main(int argc, char **argv) { for (int i = 0; i < SESSION_COUNT; i++) { int work_time_seconds = WORK_TIME_MIN * 60; int break_time_seconds = BREAK_TIME_MIN * 60; 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; }