Skip to content

Commit

Permalink
Added the "-d" option.
Browse files Browse the repository at this point in the history
It provides the user the ability to set the clock redraw frequency at
runtime.
  • Loading branch information
Cheaterman committed Jun 17, 2009
1 parent 55038fd commit a82fd71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions ttyclock.c
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ttyclock.h
Expand Up @@ -45,7 +45,6 @@
#define NORMFRAMEW 35
#define SECFRAMEW 54
#define DATEWINH 3
#define UPDATETIME 40000000
#define AMSIGN " [AM]"
#define PMSIGN " [PM]"

Expand All @@ -67,6 +66,7 @@ typedef struct
Bool rebound;
char *format;
int color;
long delay;
} option;

/* Clock geometry */
Expand Down

0 comments on commit a82fd71

Please sign in to comment.