From 3f671485658da7607f20540afda1fc996ef5c35d Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Wed, 2 Feb 2022 16:17:08 +0100 Subject: [PATCH 1/6] Fix issue #106 --- ttyclock.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index 9039310..7594a88 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -162,6 +162,8 @@ signal_handler(int signal) void cleanup(void) { + printf("\033[?25h"); + if (ttyclock.ttyscr) delscreen(ttyclock.ttyscr); @@ -232,7 +234,10 @@ draw_number(int n, int x, int y) else wattroff(ttyclock.framewin, A_BLINK); - wbkgdset(ttyclock.framewin, COLOR_PAIR(number[n][i/2])); + wbkgdset(ttyclock.framewin, COLOR_PAIR(number[n][i/2]) + ? 2*COLOR_PAIR(number[n][i/2]) | A_REVERSE + : 2*COLOR_PAIR(number[n][i/2]) | A_NORMAL + ); mvwaddch(ttyclock.framewin, x, sy, ' '); } wrefresh(ttyclock.framewin); @@ -255,14 +260,15 @@ draw_clock(void) /* Draw hour numbers */ draw_number(ttyclock.date.hour[0], 1, 1); draw_number(ttyclock.date.hour[1], 1, 8); - chtype dotcolor = COLOR_PAIR(1); + chtype dotcolor = COLOR_PAIR(2); if (ttyclock.option.blink && time(NULL) % 2 == 0) - dotcolor = COLOR_PAIR(2); + dotcolor = COLOR_PAIR(1); /* 2 dot for number separation */ - wbkgdset(ttyclock.framewin, dotcolor); + wbkgdset(ttyclock.framewin, dotcolor | A_REVERSE); mvwaddstr(ttyclock.framewin, 2, 16, " "); mvwaddstr(ttyclock.framewin, 4, 16, " "); + wbkgdset(ttyclock.framewin, dotcolor | A_NORMAL); /* Draw minute numbers */ draw_number(ttyclock.date.minute[0], 1, 20); @@ -285,9 +291,11 @@ draw_clock(void) if(ttyclock.option.second) { /* Again 2 dot for number separation */ - wbkgdset(ttyclock.framewin, dotcolor); + wbkgdset(ttyclock.framewin, dotcolor | A_REVERSE); + mvwaddstr(ttyclock.framewin, 2, NORMFRAMEW, " "); mvwaddstr(ttyclock.framewin, 4, NORMFRAMEW, " "); + wbkgdset(ttyclock.framewin, dotcolor | A_NORMAL); /* Draw second numbers */ draw_number(ttyclock.date.second[0], 1, 39); @@ -329,6 +337,8 @@ clock_move(int x, int y, int w, int h) if (ttyclock.option.box) { box(ttyclock.datewin, 0, 0); + mvwaddch(ttyclock.datewin, 0, 0, ACS_TTEE); + mvwaddch(ttyclock.datewin, 0, strlen(ttyclock.date.datestr) + 1, ACS_TTEE); } } @@ -410,6 +420,7 @@ set_box(bool b) wbkgdset(ttyclock.datewin, COLOR_PAIR(0)); box(ttyclock.framewin, 0, 0); box(ttyclock.datewin, 0, 0); + } else { wborder(ttyclock.framewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); @@ -418,6 +429,11 @@ set_box(bool b) wrefresh(ttyclock.datewin); wrefresh(ttyclock.framewin); + + if(ttyclock.option.box) { + mvwaddch(ttyclock.datewin, 0, 0, ACS_TTEE); + mvwaddch(ttyclock.datewin, 0, strlen(ttyclock.date.datestr) + 1, ACS_TTEE); + } } void @@ -553,6 +569,8 @@ main(int argc, char **argv) { int c; + printf("\033[?25l"); + /* Alloc ttyclock */ memset(&ttyclock, 0, sizeof(ttyclock_t)); From 53ee94318fb77cc077c20a772327dbf6370fd023 Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Thu, 3 Feb 2022 00:46:10 +0100 Subject: [PATCH 2/6] Add comments and simplify some expression --- ttyclock.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index 7594a88..e9559e5 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -70,9 +70,6 @@ init(void) init_pair(0, ttyclock.bg, ttyclock.bg); init_pair(1, ttyclock.bg, ttyclock.option.color); init_pair(2, ttyclock.option.color, ttyclock.bg); -// init_pair(0, ttyclock.bg, ttyclock.bg); -// init_pair(1, ttyclock.bg, ttyclock.option.color); -// init_pair(2, ttyclock.option.color, ttyclock.bg); refresh(); /* Init signal handler */ @@ -162,6 +159,7 @@ signal_handler(int signal) void cleanup(void) { + /* Turn on cursor on VT100 compatible terminals */ printf("\033[?25h"); if (ttyclock.ttyscr) @@ -234,9 +232,9 @@ draw_number(int n, int x, int y) else wattroff(ttyclock.framewin, A_BLINK); - wbkgdset(ttyclock.framewin, COLOR_PAIR(number[n][i/2]) - ? 2*COLOR_PAIR(number[n][i/2]) | A_REVERSE - : 2*COLOR_PAIR(number[n][i/2]) | A_NORMAL + wbkgdset(ttyclock.framewin, number[n][i/2] + ? COLOR_PAIR(2) | A_REVERSE + : COLOR_PAIR(0) | A_NORMAL ); mvwaddch(ttyclock.framewin, x, sy, ' '); } @@ -292,7 +290,6 @@ draw_clock(void) { /* Again 2 dot for number separation */ wbkgdset(ttyclock.framewin, dotcolor | A_REVERSE); - mvwaddstr(ttyclock.framewin, 2, NORMFRAMEW, " "); mvwaddstr(ttyclock.framewin, 4, NORMFRAMEW, " "); wbkgdset(ttyclock.framewin, dotcolor | A_NORMAL); @@ -335,6 +332,7 @@ clock_move(int x, int y, int w, int h) ttyclock.geo.y + (ttyclock.geo.w / 2) - (strlen(ttyclock.date.datestr) / 2) - 1); wresize(ttyclock.datewin, DATEWINH, strlen(ttyclock.date.datestr) + 2); + /* Draw "T" box-drawing character for joining clock and date windows */ if (ttyclock.option.box) { box(ttyclock.datewin, 0, 0); mvwaddch(ttyclock.datewin, 0, 0, ACS_TTEE); @@ -420,7 +418,6 @@ set_box(bool b) wbkgdset(ttyclock.datewin, COLOR_PAIR(0)); box(ttyclock.framewin, 0, 0); box(ttyclock.datewin, 0, 0); - } else { wborder(ttyclock.framewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); @@ -430,6 +427,7 @@ set_box(bool b) wrefresh(ttyclock.datewin); wrefresh(ttyclock.framewin); + /* Draw "T" box-drawing character for joining clock and date windows */ if(ttyclock.option.box) { mvwaddch(ttyclock.datewin, 0, 0, ACS_TTEE); mvwaddch(ttyclock.datewin, 0, strlen(ttyclock.date.datestr) + 1, ACS_TTEE); @@ -569,6 +567,7 @@ main(int argc, char **argv) { int c; + /* Turn off cursor on VT100 compatible terminals */ printf("\033[?25l"); /* Alloc ttyclock */ From c9573f120e44e7bb607265717db48382795e101c Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Thu, 3 Feb 2022 16:55:14 +0100 Subject: [PATCH 3/6] Use pre-calculated values --- ttyclock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index e9559e5..ea5058f 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -218,6 +218,8 @@ void draw_number(int n, int x, int y) { int i, sy = y; + unsigned int on = COLOR_PAIR(2) | A_REVERSE; + unsigned int off = COLOR_PAIR(0) | A_NORMAL; for(i = 0; i < 30; ++i, ++sy) { @@ -233,8 +235,8 @@ draw_number(int n, int x, int y) wattroff(ttyclock.framewin, A_BLINK); wbkgdset(ttyclock.framewin, number[n][i/2] - ? COLOR_PAIR(2) | A_REVERSE - : COLOR_PAIR(0) | A_NORMAL + ? on + : off ); mvwaddch(ttyclock.framewin, x, sy, ' '); } From 63c692857ea9af23e5c6985b628e5152bb283d5b Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Fri, 4 Feb 2022 00:39:43 +0100 Subject: [PATCH 4/6] Use more significant names for variables --- ttyclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index ea5058f..4b780a8 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -218,8 +218,8 @@ void draw_number(int n, int x, int y) { int i, sy = y; - unsigned int on = COLOR_PAIR(2) | A_REVERSE; - unsigned int off = COLOR_PAIR(0) | A_NORMAL; + unsigned int pixel_on = COLOR_PAIR(2) | A_REVERSE; + unsigned int pixel_off = COLOR_PAIR(0) | A_NORMAL; for(i = 0; i < 30; ++i, ++sy) { @@ -235,8 +235,8 @@ draw_number(int n, int x, int y) wattroff(ttyclock.framewin, A_BLINK); wbkgdset(ttyclock.framewin, number[n][i/2] - ? on - : off + ? pixel_on + : pixel_off ); mvwaddch(ttyclock.framewin, x, sy, ' '); } From 29496bc5ff63fce3477700cd306e213ff8fe260f Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Tue, 8 Feb 2022 17:20:54 +0100 Subject: [PATCH 5/6] Added comment on 'pixel_on' and 'pixel_off' variables --- ttyclock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ttyclock.c b/ttyclock.c index 4b780a8..e1fad36 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -220,6 +220,18 @@ draw_number(int n, int x, int y) int i, sy = y; unsigned int pixel_on = COLOR_PAIR(2) | A_REVERSE; unsigned int pixel_off = COLOR_PAIR(0) | A_NORMAL; + /* + * pixel_on is a bitmask made by: + * - COLOR_PAIR(2), defined by "init_color" + * - A_REVERSE is the attribute that defines reverse characters (reversed space is a big "pixel") + * + * pixel_off is anothter bitmask made by: + * - COLOR_PAIR(0) which means "not visible" + * A_NORMAL is "not reverse" attribute + * + * so "pixel_on" is used to draw "block characters" which are reversed spaces, + * "pixel_off" is used to draw the "empty space". + */ for(i = 0; i < 30; ++i, ++sy) { From 1935f70262effd9fe33b3b6affbb64d8da8d5081 Mon Sep 17 00:00:00 2001 From: Francesco Sblendorio Date: Tue, 8 Feb 2022 17:31:46 +0100 Subject: [PATCH 6/6] fix typo --- ttyclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttyclock.c b/ttyclock.c index e1fad36..a37a770 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -227,7 +227,7 @@ draw_number(int n, int x, int y) * * pixel_off is anothter bitmask made by: * - COLOR_PAIR(0) which means "not visible" - * A_NORMAL is "not reverse" attribute + * - A_NORMAL is "not reverse" attribute * * so "pixel_on" is used to draw "block characters" which are reversed spaces, * "pixel_off" is used to draw the "empty space".