Stuff.
This commit is contained in:
parent
1c737f8d7f
commit
38ab373fbe
2 changed files with 63 additions and 35 deletions
11
README.md
11
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
|
||||
|
|
87
pomodoro.c
87
pomodoro.c
|
@ -1,8 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ncurses.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue