135 lines
2.2 KiB
C
135 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include "config.h"
|
|
|
|
#if STUDY_SESSION_25
|
|
#define TIMER_S 25
|
|
#endif
|
|
|
|
|
|
#if STUDY_SESSION_50
|
|
#define TIMER_S 50
|
|
#endif
|
|
|
|
|
|
#if BREAK_TIME_5
|
|
#define TIMER_B 5
|
|
#endif
|
|
|
|
|
|
#if BREAK_TIME_10
|
|
#define TIMER_B 10
|
|
#endif
|
|
|
|
|
|
#define STUDY 0
|
|
#define BREAK 1
|
|
|
|
char help_msg[] = "\n-s integer\t\tsets length of studying session, in minutes\n"
|
|
"-b integer\t\tsets length of breaks, in minutes\n"
|
|
"-r integer\t\tnumber of sessions\n"
|
|
"-h \t\tprints help message lol \n\n";
|
|
|
|
int n_repeat = 4, time_elapsed = 0, timer_s = TIMER_S, timer_b = TIMER_B, check = 0;
|
|
long time_started = 0;
|
|
|
|
|
|
void start_timer(int);
|
|
void countdown(long, short, char*);
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
if( argv[1] != NULL ){
|
|
|
|
for(int i = 1; i < argc ; i++){
|
|
|
|
if( *(argv[i]+1) == 's')
|
|
timer_s = atoi(argv[i+1]);
|
|
|
|
if( *(argv[i]+1) == 'b' )
|
|
timer_b = atoi(argv[i+1]);
|
|
|
|
if( *(argv[i]+1) == 'r' )
|
|
n_repeat = atoi(argv[i+1]);
|
|
|
|
|
|
if( *(argv[i]+1) == 'h'){
|
|
printf("%s", help_msg);
|
|
exit(0);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
system("clear");
|
|
|
|
for(int i = 1; i <= n_repeat; i++){
|
|
|
|
printf("Session %d of %d\n\n", i, n_repeat);
|
|
|
|
start_timer(STUDY);
|
|
system("notify-send 'POMODORO' 'IT IS TIME FOR A BREAK' ");
|
|
start_timer(BREAK);
|
|
|
|
printf("%c[3F%c[2K%c[G", 27, 27, 27);
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void start_timer(int x){
|
|
|
|
time_started = time(0);
|
|
|
|
if(x == STUDY)
|
|
countdown(time_started, timer_s, "STUDY SESSION");
|
|
|
|
if(x == BREAK)
|
|
countdown(time_started, timer_b, "BREAK");
|
|
|
|
|
|
}
|
|
|
|
|
|
void countdown(long time_started, short timer, char *type){
|
|
|
|
struct timespec tim;
|
|
tim.tv_sec = 0;
|
|
tim.tv_nsec = 333000000;
|
|
|
|
int count_timer = 1;
|
|
short mins = 0, secs = 0;
|
|
|
|
|
|
while(count_timer > 0){
|
|
|
|
nanosleep(&tim, NULL);
|
|
short old_secs = secs;
|
|
|
|
time_elapsed = time(0) - time_started;
|
|
|
|
count_timer = (timer * 60) - time_elapsed;
|
|
|
|
mins = count_timer / 60;
|
|
secs = count_timer - mins * 60;
|
|
|
|
|
|
if(old_secs != secs){
|
|
printf("%s => %d:%02d\n", type, mins, secs);
|
|
printf("%c[1F%c[2K%c[G", 27, 27, 27);
|
|
}
|
|
|
|
}
|
|
}
|