merged with xorg62's current version

reverse-branch
Christian Gießen 13 years ago
commit cbe1f3a838
  1. 2
      .gitignore
  2. 2
      README
  3. 49
      ttyclock.c
  4. 2
      ttyclock.h

2
.gitignore vendored

@ -0,0 +1,2 @@
tty-clock
tty-clock.dSYM/

@ -4,6 +4,7 @@ usage : tty-clock [-scbtrvihD] [-C [0-7]] [-f format]
-C [0-7] Set the clock color -C [0-7] Set the clock color
-b Use bold colors -b Use bold colors
-t Set the hour in 12h format -t Set the hour in 12h format
-u Use UTC time
-r Do rebound the clock -r Do rebound the clock
-f format Set the date format -f format Set the date format
-v Show tty-clock version -v Show tty-clock version
@ -11,3 +12,4 @@ usage : tty-clock [-scbtrvihD] [-C [0-7]] [-f format]
-h Show this page -h Show this page
-d delay Set the delay between two redraws of the clock -d delay Set the delay between two redraws of the clock
-D Hide date -D Hide date
-B Enable blinking colon

@ -81,6 +81,9 @@ init(void)
ttyclock->geo.w = (ttyclock->option.second) ? SECFRAMEW : NORMFRAMEW; ttyclock->geo.w = (ttyclock->option.second) ? SECFRAMEW : NORMFRAMEW;
ttyclock->geo.h = 7; ttyclock->geo.h = 7;
ttyclock->tm = localtime(&(ttyclock->lt)); ttyclock->tm = localtime(&(ttyclock->lt));
if(ttyclock->option.utc) {
ttyclock->tm = gmtime(&(ttyclock->lt));
}
ttyclock->lt = time(NULL); ttyclock->lt = time(NULL);
update_hour(); update_hour();
@ -155,6 +158,9 @@ update_hour(void)
char tmpstr[128]; char tmpstr[128];
ttyclock->tm = localtime(&(ttyclock->lt)); ttyclock->tm = localtime(&(ttyclock->lt));
if(ttyclock->option.utc) {
ttyclock->tm = gmtime(&(ttyclock->lt));
}
ttyclock->lt = time(NULL); ttyclock->lt = time(NULL);
ihour = ttyclock->tm->tm_hour; ihour = ttyclock->tm->tm_hour;
@ -223,10 +229,29 @@ draw_clock(void)
draw_number(ttyclock->date.hour[0], 1, 1); draw_number(ttyclock->date.hour[0], 1, 1);
draw_number(ttyclock->date.hour[1], 1, 8); draw_number(ttyclock->date.hour[1], 1, 8);
/* 2 dot for number separation */ if (ttyclock->option.blink){
wbkgdset(ttyclock->framewin, COLOR_PAIR(1)); time_t seconds;
mvwaddstr(ttyclock->framewin, 2, 16, " "); seconds = time(NULL);
mvwaddstr(ttyclock->framewin, 4, 16, " ");
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{
/* 2 dot for number separation */
wbkgdset(ttyclock->framewin, COLOR_PAIR(1));
mvwaddstr(ttyclock->framewin, 2, 16, " ");
mvwaddstr(ttyclock->framewin, 4, 16, " ");
}
/* Draw minute numbers */ /* Draw minute numbers */
draw_number(ttyclock->date.minute[0], 1, 20); draw_number(ttyclock->date.minute[0], 1, 20);
@ -465,26 +490,30 @@ main(int argc, char **argv)
ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */
/* Default delay */ /* Default delay */
ttyclock->option.delay = 40000000; /* 25FPS */ ttyclock->option.delay = 40000000; /* 25FPS */
/* Default blink */
ttyclock->option.blink = False;
while ((c = getopt(argc, argv, "btvsrcihfDd:C:")) != -1) while ((c = getopt(argc, argv, "utvsrcihf:DBd:C:")) != -1)
{ {
switch(c) switch(c)
{ {
case 'h': case 'h':
default: default:
printf("usage : tty-clock [-scbtrvihD] [-C [0-7]] [-f format] \n" printf("usage : tty-clock [-scbtrvihDB] [-C [0-7]] [-f format] \n"
" -s Show seconds \n" " -s Show seconds \n"
" -c Set the clock at the center of the terminal \n" " -c Set the clock at the center of the terminal \n"
" -C [0-7] Set the clock color \n" " -C [0-7] Set the clock color \n"
" -b Use bold colors \n" " -b Use bold colors \n"
" -t Set the hour in 12h format \n" " -t Set the hour in 12h format \n"
" -u Use UTC time \n"
" -r Do rebound the clock \n" " -r Do rebound the clock \n"
" -f format Set the date format \n" " -f format Set the date format \n"
" -v Show tty-clock version \n" " -v Show tty-clock version \n"
" -i Show some info about tty-clock \n" " -i Show some info about tty-clock \n"
" -h Show this page \n" " -h Show this page \n"
" -d delay Set the delay between two redraws of the clock \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); free(ttyclock);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
@ -494,6 +523,9 @@ main(int argc, char **argv)
free(ttyclock->option.format); free(ttyclock->option.format);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'u':
ttyclock->option.utc = True;
break;
case 'v': case 'v':
puts("TTY-Clock 2 © devel version"); puts("TTY-Clock 2 © devel version");
free(ttyclock); free(ttyclock);
@ -529,6 +561,9 @@ main(int argc, char **argv)
case 'D': case 'D':
ttyclock->option.date = False; ttyclock->option.date = False;
break; break;
case 'B':
ttyclock->option.blink = True;
break;
} }
} }

@ -65,10 +65,12 @@ typedef struct
Bool center; Bool center;
Bool rebound; Bool rebound;
Bool date; Bool date;
Bool utc;
char *format; char *format;
int color; int color;
Bool bold; Bool bold;
long delay; long delay;
Bool blink;
} option; } option;
/* Clock geometry */ /* Clock geometry */

Loading…
Cancel
Save