From ad835677bc07e76f2c57d54b5cbe3d2b75601ab6 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sat, 1 Jun 2013 23:21:37 -0500 Subject: [PATCH] (maint) Add blink colon option Prior to this commit, my blinking colon pull req made blinking default. This commit makes it so that you have to pass in a flag -B to make the colons blink. This fits with the style of this program. --- README | 1 + ttyclock.c | 46 ++++++++++++++++++++++++++++++---------------- ttyclock.h | 1 + 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README b/README index e18294d..dc82c6b 100755 --- a/README +++ b/README @@ -8,3 +8,4 @@ usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] -v Show tty-clock version -i Show some info about tty-clock -h Show this page + -B Enable blinking colon diff --git a/ttyclock.c b/ttyclock.c index bb7043b..743e269 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -207,20 +207,28 @@ draw_clock(void) draw_number(ttyclock->date.hour[0], 1, 1); draw_number(ttyclock->date.hour[1], 1, 8); - time_t seconds; - seconds = time(NULL); - - if (seconds % 2 != 0){ - /* 2 dot for number separation */ - wbkgdset(ttyclock->framewin, COLOR_PAIR(1)); - mvwaddstr(ttyclock->framewin, 2, 16, " "); - mvwaddstr(ttyclock->framewin, 4, 16, " "); + if (ttyclock->option.blink){ + time_t seconds; + seconds = time(NULL); + + if (seconds % 2 != 0){ + /* 2 dot for number separation */ + wbkgdset(ttyclock->framewin, COLOR_PAIR(1)); + mvwaddstr(ttyclock->framewin, 2, 16, " "); + mvwaddstr(ttyclock->framewin, 4, 16, " "); + } + else if (seconds % 2 == 0){ + /*2 dot black for blinking */ + wbkgdset(ttyclock->framewin, COLOR_PAIR(2)); + mvwaddstr(ttyclock->framewin, 2, 16, " "); + mvwaddstr(ttyclock->framewin, 4, 16, " "); + } } - else if (seconds % 2 == 0){ - /*2 dot black for blinking */ - wbkgdset(ttyclock->framewin, COLOR_PAIR(2)); - mvwaddstr(ttyclock->framewin, 2, 16, " "); - mvwaddstr(ttyclock->framewin, 4, 16, " "); + else{ + /* 2 dot for number separation */ + wbkgdset(ttyclock->framewin, COLOR_PAIR(1)); + mvwaddstr(ttyclock->framewin, 2, 16, " "); + mvwaddstr(ttyclock->framewin, 4, 16, " "); } /* Draw minute numbers */ @@ -448,14 +456,16 @@ main(int argc, char **argv) ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ + /* Default blink */ + ttyclock->option.blink = False; - while ((c = getopt(argc, argv, "tvsrcihfDd:C:")) != -1) + while ((c = getopt(argc, argv, "tvsrcihfDBd:C:")) != -1) { switch(c) { case 'h': default: - printf("usage : tty-clock [-sctrvihD] [-C [0-7]] [-f format] \n" + printf("usage : tty-clock [-sctrvihDB] [-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" @@ -466,7 +476,8 @@ main(int argc, char **argv) " -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" - " -D Hide date \n"); + " -D Hide date \n" + " -B Enable blinking colon \n"); free(ttyclock); exit(EXIT_SUCCESS); break; @@ -508,6 +519,9 @@ main(int argc, char **argv) case 'D': ttyclock->option.date = False; break; + case 'B': + ttyclock->option.blink = True; + break; } } diff --git a/ttyclock.h b/ttyclock.h index d6048f3..469e8f7 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -68,6 +68,7 @@ typedef struct char *format; int color; long delay; + Bool blink; } option; /* Clock geometry */