sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 41a974203782cf6282c203fd7c16279afc0a10b3
parent 211c565b3d560ad16ef20359d6efe37d0783c583
Author: sin <sin@2f30.org>
Date:   Sat, 21 Nov 2015 10:19:19 +0000

cal: Highlight current day

Thanks cls!

Diffstat:
Mcal.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/cal.c b/cal.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <unistd.h> #include "util.h" @@ -11,6 +12,8 @@ enum { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; enum caltype { JULIAN, GREGORIAN }; enum { TRANS_YEAR = 1752, TRANS_MONTH = SEP, TRANS_DAY = 2 }; +static struct tm *ltime; + static int isleap(size_t year, enum caltype cal) { @@ -56,6 +59,7 @@ printgrid(size_t year, int month, int fday, int line) { enum caltype cal; int offset, dom, d = 0, trans; /* are we in the transition from Julian to Gregorian? */ + int today = 0; cal = (year < TRANS_YEAR || (year == TRANS_YEAR && month <= TRANS_MONTH)) ? JULIAN : GREGORIAN; trans = (year == TRANS_YEAR && month == TRANS_MONTH); @@ -72,8 +76,13 @@ printgrid(size_t year, int month, int fday, int line) if (trans && !(line == 2 && fday == 3)) dom += 11; } + if (ltime && year == ltime->tm_year + 1900 && month == ltime->tm_mon) + today = ltime->tm_mday; for (; d < 7 && dom <= monthlength(year, month, cal); ++d, ++dom) { - printf("%2d ", dom); + if (dom == today) + printf("\x1b[7m%2d\x1b[0m ", dom); /* highlight today's date */ + else + printf("%2d ", dom); if (trans && dom == TRANS_DAY) dom += 11; } @@ -136,7 +145,6 @@ usage(void) int main(int argc, char *argv[]) { - struct tm *ltime; time_t now; size_t year, ncols, nmons; int fday, month; @@ -147,6 +155,9 @@ main(int argc, char *argv[]) month = ltime->tm_mon + 1; fday = 0; + if (!isatty(STDOUT_FILENO)) + ltime = NULL; /* don't highlight today's date */ + ncols = 3; nmons = 0;