Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions ttyclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,15 @@ void
update_hour(void)
{
int ihour;
int ms;
char tmpstr[128];

ttyclock.lt = time(NULL);
struct timeval tv;
gettimeofday(&tv, NULL);

ttyclock.lt = tv.tv_sec;
ms = tv.tv_usec / 1000;

ttyclock.tm = localtime(&(ttyclock.lt));
if(ttyclock.option.utc) {
ttyclock.tm = gmtime(&(ttyclock.lt));
Expand Down Expand Up @@ -214,6 +220,11 @@ update_hour(void)
ttyclock.date.second[0] = ttyclock.tm->tm_sec / 10;
ttyclock.date.second[1] = ttyclock.tm->tm_sec % 10;

/* Set milliseconds */
ttyclock.date.ms[0] = ms / 100;
ttyclock.date.ms[1] = (ms % 100) / 10;
ttyclock.date.ms[2] = (ms % 100) % 10;

return;
}

Expand Down Expand Up @@ -288,6 +299,19 @@ draw_clock(void)
draw_number(ttyclock.date.second[1], 1, 46);
}

/* Draw milliseconds if the option is enable */
if(ttyclock.option.millisecond)
{
/* Again 2 dot for number separation */
wbkgdset(ttyclock.framewin, dotcolor);
mvwaddstr(ttyclock.framewin, 5, 54, " ");

/* Draw second numbers */
draw_number(ttyclock.date.ms[0], 1, 58);
draw_number(ttyclock.date.ms[1], 1, 65);
draw_number(ttyclock.date.ms[2], 1, 72);
}

return;
}

Expand Down Expand Up @@ -548,20 +572,21 @@ main(int argc, char **argv)
/* Default color */
ttyclock.option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */
/* Default delay */
ttyclock.option.delay = 1; /* 1FPS */
ttyclock.option.nsdelay = 0; /* -0FPS */
ttyclock.option.delay = 0; /* 100FPS */
ttyclock.option.nsdelay = 10 * 1000 * 1000; /* 10ms */
ttyclock.option.blink = False;

atexit(cleanup);

while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:")) != -1)
while ((c = getopt(argc, argv, "iuvsmScbtrhBxnDC:f:d:T:a:")) != -1)
{
switch(c)
{
case 'h':
default:
printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n"
" -s Show seconds \n"
" -m Show milliseconds \n"
" -S Screensaver mode \n"
" -x Show box \n"
" -c Set the clock at the center of the terminal \n"
Expand Down Expand Up @@ -596,6 +621,9 @@ main(int argc, char **argv)
case 's':
ttyclock.option.second = True;
break;
case 'm':
ttyclock.option.millisecond = True;
break;
case 'S':
ttyclock.option.screensaver = True;
break;
Expand Down
4 changes: 3 additions & 1 deletion ttyclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

/* Macro */
#define NORMFRAMEW 35
#define SECFRAMEW 54
#define SECFRAMEW 100
#define DATEWINH 3
#define AMSIGN " [AM]"
#define PMSIGN " [PM]"
Expand All @@ -70,6 +70,7 @@ typedef struct
struct
{
Bool second;
Bool millisecond;
Bool screensaver;
Bool twelve;
Bool center;
Expand Down Expand Up @@ -100,6 +101,7 @@ typedef struct
unsigned int hour[2];
unsigned int minute[2];
unsigned int second[2];
unsigned int ms[3];
char datestr[256];
} date;

Expand Down