From ed0895aab6142ba4f190ef186c85b7cb145778d1 Mon Sep 17 00:00:00 2001 From: John Boyle Date: Wed, 1 May 2019 09:35:46 -0700 Subject: [PATCH 1/3] add screensaver-mode color cycling option (1 / min) --- ttyclock.c | 15 ++++++++++++++- ttyclock.h | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index 558d9b2..7aaf008 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -178,12 +178,21 @@ update_hour(void) int ihour; char tmpstr[128]; + int iminute_old = ttyclock.tm->tm_min; + ttyclock.lt = time(NULL); ttyclock.tm = localtime(&(ttyclock.lt)); if(ttyclock.option.utc) { ttyclock.tm = gmtime(&(ttyclock.lt)); } + if(ttyclock.option.color_cycle && iminute_old != ttyclock.tm->tm_min) + { + ttyclock.option.color = (ttyclock.option.color + 1) % 8; + init_pair(1, ttyclock.bg, ttyclock.option.color); + init_pair(2, ttyclock.option.color, ttyclock.bg);; + } + ihour = ttyclock.tm->tm_hour; if(ttyclock.option.twelve) @@ -554,7 +563,7 @@ main(int argc, char **argv) atexit(cleanup); - while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:")) != -1) + while ((c = getopt(argc, argv, "iuvsScbtrhBxXnDC:f:d:T:a:")) != -1) { switch(c) { @@ -563,6 +572,7 @@ main(int argc, char **argv) printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" + " -X Screensaver color cycle \n" " -x Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" @@ -599,6 +609,9 @@ main(int argc, char **argv) case 'S': ttyclock.option.screensaver = True; break; + case 'X': + ttyclock.option.color_cycle = True; + break; case 'c': ttyclock.option.center = True; break; diff --git a/ttyclock.h b/ttyclock.h index ba8fe24..311f44d 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -79,11 +79,12 @@ typedef struct Bool box; Bool noquit; char format[100]; - int color; + unsigned int color; Bool bold; long delay; Bool blink; long nsdelay; + Bool color_cycle; } option; /* Clock geometry */ From 3695d80df6d4d62a1610bb8cb94f8d47c60b6a57 Mon Sep 17 00:00:00 2001 From: John Boyle Date: Wed, 1 May 2019 09:46:04 -0700 Subject: [PATCH 2/3] update README and man page --- README | 39 ++++++++++++++++++++------------------- tty-clock.1 | 3 +++ ttyclock.c | 6 +++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README b/README index 2a37ae5..53483ea 100644 --- a/README +++ b/README @@ -1,20 +1,21 @@ -usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] - -s Show seconds - -S Screensaver mode - -x Show box - -c Set the clock at the center of the terminal - -C [0-7] Set the clock color - -b Use bold colors - -t Set the hour in 12h format - -u Use UTC time - -T tty Display the clock on the specified terminal - -r Do rebound the clock - -f format Set the date format - -n Don't quit on keypress - -v Show tty-clock version - -i Show some info about tty-clock - -h Show this page - -D Hide date - -B Enable blinking colon - -d delay Set the delay between two redraws of the clock. Default 1s. +usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] + -s Show seconds + -S Screensaver mode + -X Screensaver color cycle (1/min) + -x Show box + -c Set the clock at the center of the terminal + -C [0-7] Set the clock color + -b Use bold colors + -t Set the hour in 12h format + -u Use UTC time + -T tty Display the clock on the specified terminal + -r Do rebound the clock + -f format Set the date format + -n Don't quit on keypress + -v Show tty-clock version + -i Show some info about tty-clock + -h Show this page + -D Hide date + -B Enable blinking colon + -d delay Set the delay between two redraws of the clock. Default 1s. -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns. diff --git a/tty-clock.1 b/tty-clock.1 index 5343444..eb54562 100644 --- a/tty-clock.1 +++ b/tty-clock.1 @@ -56,6 +56,9 @@ Show seconds. \fB\-S\fR Screensaver mode. tty\-clock terminates when any key is pressed. .TP +\fB\-X\fR +Screensaver color cycle, once per minute. +.TP \fB\-x\fR Show box. .TP diff --git a/ttyclock.c b/ttyclock.c index 7aaf008..0a827d3 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -572,17 +572,17 @@ main(int argc, char **argv) printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" - " -X Screensaver color cycle \n" + " -X Screensaver color cycle (1/min) \n" " -x Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" " -b Use bold colors \n" " -t Set the hour in 12h format \n" " -u Use UTC time \n" - " -T tty Display the clock on the specified terminal \n" + " -T tty Display the clock on the specified terminal \n" " -r Do rebound the clock \n" " -f format Set the date format \n" - " -n Don't quit on keypress \n" + " -n Don't quit on keypress \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" From 0bee61e3511bbe1ee7f694bd58c1377c45e31fe8 Mon Sep 17 00:00:00 2001 From: John Boyle Date: Wed, 6 Jan 2021 20:53:10 -0800 Subject: [PATCH 3/3] fixes --- Makefile | 4 ++-- ttyclock.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ea8951c..915058e 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ else ifeq ($(shell sh -c 'which ncursesw5-config>/dev/null 2>/dev/null && echo y CFLAGS += -Wall -g $$(ncursesw5-config --cflags) LDFLAGS += $$(ncursesw5-config --libs) else - CFLAGS += -Wall -g $$(pkg-config --cflags ncurses) - LDFLAGS += $$(pkg-config --libs ncurses) + CFLAGS += -Wall + LDFLAGS += -lncurses endif tty-clock : ${SRC} diff --git a/ttyclock.c b/ttyclock.c index 0a827d3..6afbd4f 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -436,10 +436,10 @@ key_event(void) if(c != ERR && ttyclock.option.noquit == False) { ttyclock.running = False; + return; } else { - nanosleep(&length, NULL); for(i = 0; i < 8; ++i) if(c == (i + '0')) { @@ -448,6 +448,7 @@ key_event(void) init_pair(2, i, ttyclock.bg); } } + nanosleep(&length, NULL); return; }