From 38ab373fbe4e05cc4ee12ddfcbca359fc55968fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=88=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=82=D0=BE=D0=BA=D0=B8?= =?UTF-8?q?=D1=9B-=D0=A8=D1=83=D0=BC=D0=B0=D1=80=D0=B0=D1=86?= Date: Wed, 29 Sep 2021 14:21:25 +0200 Subject: [PATCH] Stuff. --- README.md | 11 +++++-- pomodoro.c | 87 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 04ecb1b..8a55879 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ -A simple cli interfaced pomodoro study timer. Edit config.h to change between 25 or 50 minute study sessions as well as 5 or 10 minute breaks. +# Pomodoro +A simple cli interfaced pomodoro study timer. + +Edit config.h to change between 25 or 50 minute study sessions as well as 5 or 10 minute breaks. Also, you can get help with -pomodoro -h +` pomodoro -h + +# Compiling + +` gcc pomodoro.c -o pomodoro -lncurses diff --git a/pomodoro.c b/pomodoro.c index aab5120..567ab32 100644 --- a/pomodoro.c +++ b/pomodoro.c @@ -1,8 +1,9 @@ -#include #include #include +#include #include "config.h" + #if STUDY_SESSION_25 #define TIMER_S 25 #endif @@ -31,13 +32,13 @@ char help_msg[] = "\n-s integer\t\tsets length of studying session, 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 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*); - +void start_timer(int, int); +void countdown(long, short, char*, int); +void fact_check(char*, long int*); int main(int argc, char *argv[]){ @@ -46,40 +47,44 @@ int main(int argc, char *argv[]){ for(int i = 1; i < argc ; i++){ - if( *(argv[i]+1) == 's') - timer_s = atoi(argv[i+1]); + switch ( *(argv[i]+1) ){ - if( *(argv[i]+1) == 'b' ) - timer_b = atoi(argv[i+1]); + case 'h': + printf("%s", help_msg); + exit(0); + break; - if( *(argv[i]+1) == 'r' ) - n_repeat = atoi(argv[i+1]); + case 's': + fact_check(argv[i+1], &timer_s); + break; + case 'b': + fact_check(argv[i+1], &timer_b); + break; + + case 'r': + fact_check(argv[i+1], &n_repeat); + break; - if( *(argv[i]+1) == 'h'){ - printf("%s", help_msg); - exit(0); } - } } - - system("clear"); + initscr(); + noecho(); for(int i = 1; i <= n_repeat; i++){ - printf("Session %d of %d\n\n", i, n_repeat); - - start_timer(STUDY); + + start_timer(STUDY, i); system("notify-send 'POMODORO' 'IT IS TIME FOR A BREAK' "); - start_timer(BREAK); - - printf("%c[3F%c[2K%c[G", 27, 27, 27); + start_timer(BREAK, i); + + } - + endwin(); return 0; } @@ -89,35 +94,37 @@ int main(int argc, char *argv[]){ -void start_timer(int x){ +void start_timer(int x, int i){ time_started = time(0); if(x == STUDY) - countdown(time_started, timer_s, "STUDY SESSION"); + countdown(time_started, timer_s, "STUDY SESSION", i); if(x == BREAK) - countdown(time_started, timer_b, "BREAK"); + countdown(time_started, timer_b, "BREAK", i); } -void countdown(long time_started, short timer, char *type){ +void countdown(long time_started, short timer, char *type, int i){ struct timespec tim; tim.tv_sec = 0; tim.tv_nsec = 333000000; - int count_timer = 1; + int count_timer = 1, x, y; short mins = 0, secs = 0; while(count_timer > 0){ - + nanosleep(&tim, NULL); short old_secs = secs; + short ch; + time_elapsed = time(0) - time_started; count_timer = (timer * 60) - time_elapsed; @@ -127,9 +134,23 @@ void countdown(long time_started, short timer, char *type){ if(old_secs != secs){ - printf("%s => %d:%02d\n", type, mins, secs); - printf("%c[1F%c[2K%c[G", 27, 27, 27); - } + printw("Session %d of %d\n\n", i, n_repeat); + printw("%s => %d:%02d", type, mins, secs); + refresh(); + + clear(); + move(0, 0); + + } + } } + +void fact_check(char *arg, long int *result) { + *result = strtol(arg, NULL, 10); +} + + + +