This commit is contained in:
Јован Ђокић-Шумарац 2021-09-29 14:21:25 +02:00
parent 1c737f8d7f
commit 38ab373fbe
2 changed files with 63 additions and 35 deletions

View file

@ -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 Also, you can get help with
pomodoro -h ` pomodoro -h
# Compiling
` gcc pomodoro.c -o pomodoro -lncurses

View file

@ -1,8 +1,9 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <ncurses.h>
#include "config.h" #include "config.h"
#if STUDY_SESSION_25 #if STUDY_SESSION_25
#define TIMER_S 25 #define TIMER_S 25
#endif #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" "-r integer\t\tnumber of sessions\n"
"-h \t\tprints help message lol \n\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; long time_started = 0;
void start_timer(int); void start_timer(int, int);
void countdown(long, short, char*); void countdown(long, short, char*, int);
void fact_check(char*, long int*);
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
@ -46,40 +47,44 @@ int main(int argc, char *argv[]){
for(int i = 1; i < argc ; i++){ for(int i = 1; i < argc ; i++){
if( *(argv[i]+1) == 's') switch ( *(argv[i]+1) ){
timer_s = atoi(argv[i+1]);
if( *(argv[i]+1) == 'b' ) case 'h':
timer_b = atoi(argv[i+1]); printf("%s", help_msg);
exit(0);
break;
if( *(argv[i]+1) == 'r' ) case 's':
n_repeat = atoi(argv[i+1]); 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);
} }
} }
} }
initscr();
system("clear"); noecho();
for(int i = 1; i <= n_repeat; i++){ 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' "); system("notify-send 'POMODORO' 'IT IS TIME FOR A BREAK' ");
start_timer(BREAK); start_timer(BREAK, i);
printf("%c[3F%c[2K%c[G", 27, 27, 27);
} }
endwin();
return 0; return 0;
} }
@ -89,27 +94,27 @@ int main(int argc, char *argv[]){
void start_timer(int x){ void start_timer(int x, int i){
time_started = time(0); time_started = time(0);
if(x == STUDY) if(x == STUDY)
countdown(time_started, timer_s, "STUDY SESSION"); countdown(time_started, timer_s, "STUDY SESSION", i);
if(x == BREAK) 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; struct timespec tim;
tim.tv_sec = 0; tim.tv_sec = 0;
tim.tv_nsec = 333000000; tim.tv_nsec = 333000000;
int count_timer = 1; int count_timer = 1, x, y;
short mins = 0, secs = 0; short mins = 0, secs = 0;
@ -117,6 +122,8 @@ void countdown(long time_started, short timer, char *type){
nanosleep(&tim, NULL); nanosleep(&tim, NULL);
short old_secs = secs; short old_secs = secs;
short ch;
time_elapsed = time(0) - time_started; time_elapsed = time(0) - time_started;
@ -127,9 +134,23 @@ void countdown(long time_started, short timer, char *type){
if(old_secs != secs){ if(old_secs != secs){
printf("%s => %d:%02d\n", type, mins, secs); printw("Session %d of %d\n\n", i, n_repeat);
printf("%c[1F%c[2K%c[G", 27, 27, 27); 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);
}