commit 863c5174b2f00c372cfb1173e88caab7e36210f0 Author: Јован Ђокић-Шумарац Date: Mon Sep 27 20:31:27 2021 +0200 Initial commit diff --git a/config.h b/config.h new file mode 100644 index 0000000..d0f54aa --- /dev/null +++ b/config.h @@ -0,0 +1,10 @@ + + +#define STUDY_SESSION_25 1 + +#define STUDY_SESSION_50 0 + +#define BREAK_TIME_5 1 + +#define BREAK_TIME_10 0 + diff --git a/p b/p new file mode 100755 index 0000000..6195afa Binary files /dev/null and b/p differ diff --git a/pomodoro.c b/pomodoro.c new file mode 100644 index 0000000..5facbbf --- /dev/null +++ b/pomodoro.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#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 + + + +int n_repeat = 0, time_elapsed = 0, timer_s = TIMER_S, timer_b = TIMER_B, check = 0; +long time_started = 0; + + +void get_stuff(void); +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]); + + } + } + + get_stuff(); + + + system("clear"); + + for(int i = 1; i <= n_repeat; i++){ + + printf("Session %d\n\n", i); + + start_timer(STUDY); + start_timer(BREAK); + + printf("%c[3F%c[2K%c[G", 27, 27, 27); + } + + + return 0; +} + + + + + +void get_stuff(void){ + + printf("Enter number of pomodoro sessions (%d minute periods with %d minute breaks) : ", timer_s, timer_b); + + if ( !(scanf("%d", &n_repeat)) ){ + printf("\n\nThat's not a number you globussaire\n\n"); + fprintf(stderr, 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); + } + + } +}