From 3594e6276b54f4508e969ec7b4a9c723ce6a2bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Wed, 5 May 2010 14:24:20 +0200 Subject: [PATCH 1/3] Add option (-b) to show border, default not shown --- README | 22 ++++++++++++---------- ttyclock.c | 16 ++++++++++++---- ttyclock.h | 1 + 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README b/README index e18294d..2942123 100755 --- a/README +++ b/README @@ -1,10 +1,12 @@ -usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] - -s Show seconds - -c Set the clock at the center of the terminal - -C [0-7] Set the clock color - -t Set the hour in 12h format - -r Do rebound the clock - -f format Set the date format - -v Show tty-clock version - -i Show some info about tty-clock - -h Show this page +usage : tty-clock [-sbctrvih] [-C [0-7]] [-f format] [-d delay] + -s Show seconds + -b Show box + -c Set the clock at the center of the terminal + -C [0-7] Set the clock color + -t Set the hour in 12h format + -r Do rebound the clock + -f format Set the date format + -v Show tty-clock version + -i Show some info about tty-clock + -h Show this page + -d delay Set the delay between two redraws of the clock diff --git a/ttyclock.c b/ttyclock.c index 8fa2306..5014803 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -86,14 +86,18 @@ init(void) ttyclock->geo.w, ttyclock->geo.x, ttyclock->geo.y); - box(ttyclock->framewin, 0, 0); + if(ttyclock->option.box) { + box(ttyclock->framewin, 0, 0); + } /* Create the date win */ ttyclock->datewin = newwin(DATEWINH, strlen(ttyclock->date.datestr) + 2, ttyclock->geo.x + ttyclock->geo.h - 1, ttyclock->geo.y + (ttyclock->geo.w / 2) - (strlen(ttyclock->date.datestr) / 2) - 1); - box(ttyclock->datewin, 0, 0); + if(ttyclock->option.box) { + box(ttyclock->datewin, 0, 0); + } clearok(ttyclock->datewin, True); set_center(ttyclock->option.center); @@ -420,14 +424,15 @@ main(int argc, char **argv) /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ - while ((c = getopt(argc, argv, "tvsrcihfd:C:")) != -1) + while ((c = getopt(argc, argv, "tvsrcihfbd:C:")) != -1) { switch(c) { case 'h': default: - printf("usage : tty-clock [-sctrvih] [-C [0-7]] [-f format] \n" + printf("usage : tty-clock [-sbctrvih] [-C [0-7]] [-f format] [-d delay] \n" " -s Show seconds \n" + " -b Show box \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" @@ -475,6 +480,9 @@ main(int argc, char **argv) if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; + case 'b': + ttyclock->option.box = True; + break; } } diff --git a/ttyclock.h b/ttyclock.h index 911aa20..e136751 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -64,6 +64,7 @@ typedef struct Bool twelve; Bool center; Bool rebound; + Bool box; char *format; int color; long delay; From 8502f635db47715ae3f1c157debffbc3dc363b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Wed, 5 May 2010 15:55:34 +0200 Subject: [PATCH 2/3] Press 'b' to switch box on/off --- ttyclock.c | 35 +++++++++++++++++++++++++++++++++-- ttyclock.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ttyclock.c b/ttyclock.c index 5014803..237bd74 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -258,8 +258,10 @@ 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); - box(ttyclock->framewin, 0, 0); - box(ttyclock->datewin, 0, 0); + if(ttyclock->option.box) { + box(ttyclock->framewin, 0, 0); + box(ttyclock->datewin, 0, 0); + } wrefresh(ttyclock->datewin); wrefresh(ttyclock->framewin); @@ -322,6 +324,29 @@ set_center(Bool b) return; } +void +set_box(Bool b) +{ + ttyclock->option.box = b; + + wbkgdset(ttyclock->framewin, COLOR_PAIR(0)); + wbkgdset(ttyclock->datewin, COLOR_PAIR(0)); + + if(ttyclock->option.box) { + wbkgdset(ttyclock->framewin, COLOR_PAIR(0)); + wbkgdset(ttyclock->datewin, COLOR_PAIR(0)); + box(ttyclock->framewin, 0, 0); + box(ttyclock->datewin, 0, 0); + } + else { + wborder(ttyclock->framewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wborder(ttyclock->datewin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + } + + wrefresh(ttyclock->datewin); + wrefresh(ttyclock->framewin); +} + void key_event(void) { @@ -392,6 +417,12 @@ key_event(void) if(ttyclock->option.rebound && ttyclock->option.center) ttyclock->option.center = False; break; + + case 'b': + case 'B': + set_box(!ttyclock->option.box); + break; + default: nanosleep(&length, NULL); for(i = 0; i < 8; ++i) diff --git a/ttyclock.h b/ttyclock.h index e136751..08c8a32 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -107,6 +107,7 @@ void draw_clock(void); void clock_move(int x, int y, int w, int h); void set_second(void); void set_center(Bool b); +void set_box(Bool b); void key_event(void); /* Global variable */ From ab96db2e4e160fdf83f8110f3b31e7c3e8e452e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Wed, 5 May 2010 16:07:26 +0200 Subject: [PATCH 3/3] Correct format specification bug --- ttyclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttyclock.c b/ttyclock.c index 237bd74..052922c 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -455,7 +455,7 @@ main(int argc, char **argv) /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ - while ((c = getopt(argc, argv, "tvsrcihfbd:C:")) != -1) + while ((c = getopt(argc, argv, "tvsrcihbf:d:C:")) != -1) { switch(c) {