diff --git a/README b/README index e18294d..75307d5 100644 --- a/README +++ b/README @@ -1,5 +1,6 @@ -usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] +usage : tty-clock [-sSctrvih] [-C [0-7]] [-f format] -s Show seconds + -S Screensaver mode -c Set the clock at the center of the terminal -C [0-7] Set the clock color -t Set the hour in 12h format diff --git a/ttyclock.c b/ttyclock.c index f4d3ad3..5bd372e 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -333,6 +333,28 @@ key_event(void) int i, c; struct timespec length = { 0, ttyclock->option.delay }; + + if (ttyclock->option.screensaver) + { + c = wgetch(stdscr); + if(c != ERR) + { + ttyclock->running = False; + } + else + { + nanosleep(&length, NULL); + for(i = 0; i < 8; ++i) + if(c == (i + '0')) + { + ttyclock->option.color = i; + init_pair(1, ttyclock->bg, i); + init_pair(2, i, ttyclock->bg); + } + } + return; + } + switch(c = wgetch(stdscr)) { @@ -431,14 +453,15 @@ main(int argc, char **argv) atexit(cleanup); - while ((c = getopt(argc, argv, "tvsrcihf:d:C:")) != -1) + while ((c = getopt(argc, argv, "tvsSrcihf:d:C:")) != -1) { switch(c) { case 'h': default: - printf("usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] \n" + printf("usage : tty-clock [-sSctrvih] [-C [0-7]] [-f format] \n" " -s Show seconds \n" + " -S Screensaver mode \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" @@ -461,6 +484,9 @@ main(int argc, char **argv) case 's': ttyclock->option.second = True; break; + case 'S': + ttyclock->option.screensaver = True; + break; case 'c': ttyclock->option.center = True; break; diff --git a/ttyclock.h b/ttyclock.h index 911aa20..d464195 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -61,6 +61,7 @@ typedef struct struct { Bool second; + Bool screensaver; Bool twelve; Bool center; Bool rebound;