diff --git a/ttyclock.c b/ttyclock.c index fb5ec2e..8fa2306 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -323,7 +323,7 @@ key_event(void) { int i, c; - struct timespec length = { 0, UPDATETIME }; + struct timespec length = { 0, ttyclock->option.delay }; switch(c = wgetch(stdscr)) { @@ -417,23 +417,26 @@ main(int argc, char **argv) strncpy(ttyclock->option.format, "%d/%m/%Y", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ + /* Default delay */ + ttyclock->option.delay = 40000000; /* 25FPS */ - while ((c = getopt(argc, argv, "tvsrcihf:C:")) != -1) + while ((c = getopt(argc, argv, "tvsrcihfd:C:")) != -1) { switch(c) { case 'h': default: - printf("usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] \n" - " -s Show seconds \n" - " -c Set the clock at the center of the terminal \n" - " -C [0-7] Set the clock color \n" - " -t Set the hour in 12h format \n" - " -r Do rebound the clock \n" - " -f format Set the date format \n" - " -v Show tty-clock version \n" - " -i Show some info about tty-clock \n" - " -h Show this page \n"); + printf("usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] \n" + " -s Show seconds \n" + " -c Set the clock at the center of the terminal \n" + " -C [0-7] Set the clock color \n" + " -t Set the hour in 12h format \n" + " -r Do rebound the clock \n" + " -f format Set the date format \n" + " -v Show tty-clock version \n" + " -i Show some info about tty-clock \n" + " -h Show this page \n" + " -d delay Set the delay between two redraws of the clock \n"); free(ttyclock); exit(EXIT_SUCCESS); break; @@ -468,6 +471,10 @@ main(int argc, char **argv) case 'f': strncpy(ttyclock->option.format, optarg, 100); break; + case 'd': + if(atol(optarg) >= 0 && atol(optarg) < 1000000000) + ttyclock->option.delay = atol(optarg); + break; } } diff --git a/ttyclock.h b/ttyclock.h index 97b232c..911aa20 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -45,7 +45,6 @@ #define NORMFRAMEW 35 #define SECFRAMEW 54 #define DATEWINH 3 -#define UPDATETIME 40000000 #define AMSIGN " [AM]" #define PMSIGN " [PM]" @@ -67,6 +66,7 @@ typedef struct Bool rebound; char *format; int color; + long delay; } option; /* Clock geometry */