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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
39 changes: 20 additions & 19 deletions README
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions tty-clock.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions ttyclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -427,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'))
{
Expand All @@ -439,6 +448,7 @@ key_event(void)
init_pair(2, i, ttyclock.bg);
}
}
nanosleep(&length, NULL);
return;
}

Expand Down Expand Up @@ -554,7 +564,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)
{
Expand All @@ -563,16 +573,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 (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"
Expand All @@ -599,6 +610,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;
Expand Down
3 changes: 2 additions & 1 deletion ttyclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down