@@ -349,11 +349,27 @@ def formatday(self, day, weekday, width):
349349 s = '%2i' % day # right-align single-digit days
350350 return s .center (width )
351351
352- def formatweek (self , theweek , width ):
352+ def formatweek (self , theweek , width , * , highlight_day = None ):
353353 """
354354 Returns a single week in a string (no newline).
355355 """
356- return ' ' .join (self .formatday (d , wd , width ) for (d , wd ) in theweek )
356+ if highlight_day :
357+ from _colorize import get_colors
358+
359+ ansi = get_colors ()
360+ highlight = f"{ ansi .BLACK } { ansi .BACKGROUND_YELLOW } "
361+ reset = ansi .RESET
362+ else :
363+ highlight = reset = ""
364+
365+ return ' ' .join (
366+ (
367+ f"{ highlight } { self .formatday (d , wd , width )} { reset } "
368+ if d == highlight_day
369+ else self .formatday (d , wd , width )
370+ )
371+ for (d , wd ) in theweek
372+ )
357373
358374 def formatweekday (self , day , width ):
359375 """
@@ -388,10 +404,11 @@ def prmonth(self, theyear, themonth, w=0, l=0):
388404 """
389405 print (self .formatmonth (theyear , themonth , w , l ), end = '' )
390406
391- def formatmonth (self , theyear , themonth , w = 0 , l = 0 ):
407+ def formatmonth (self , theyear , themonth , w = 0 , l = 0 , * , highlight_day = None ):
392408 """
393409 Return a month's calendar string (multi-line).
394410 """
411+ highlight_day = highlight_day .day if highlight_day else None
395412 w = max (2 , w )
396413 l = max (1 , l )
397414 s = self .formatmonthname (theyear , themonth , 7 * (w + 1 ) - 1 )
@@ -400,11 +417,11 @@ def formatmonth(self, theyear, themonth, w=0, l=0):
400417 s += self .formatweekheader (w ).rstrip ()
401418 s += '\n ' * l
402419 for week in self .monthdays2calendar (theyear , themonth ):
403- s += self .formatweek (week , w ).rstrip ()
420+ s += self .formatweek (week , w , highlight_day = highlight_day ).rstrip ()
404421 s += '\n ' * l
405422 return s
406423
407- def formatyear (self , theyear , w = 2 , l = 1 , c = 6 , m = 3 ):
424+ def formatyear (self , theyear , w = 2 , l = 1 , c = 6 , m = 3 , * , highlight_day = None ):
408425 """
409426 Returns a year's calendar as a multi-line string.
410427 """
@@ -428,15 +445,24 @@ def formatyear(self, theyear, w=2, l=1, c=6, m=3):
428445 headers = (header for k in months )
429446 a (formatstring (headers , colwidth , c ).rstrip ())
430447 a ('\n ' * l )
448+
449+ if highlight_day and highlight_day .month in months :
450+ month_pos = months .index (highlight_day .month )
451+ else :
452+ month_pos = None
453+
431454 # max number of weeks for this row
432455 height = max (len (cal ) for cal in row )
433456 for j in range (height ):
434457 weeks = []
435- for cal in row :
458+ for k , cal in enumerate ( row ) :
436459 if j >= len (cal ):
437460 weeks .append ('' )
438461 else :
439- weeks .append (self .formatweek (cal [j ], w ))
462+ day = highlight_day .day if k == month_pos else None
463+ weeks .append (
464+ self .formatweek (cal [j ], w , highlight_day = day )
465+ )
440466 a (formatstring (weeks , colwidth , c ).rstrip ())
441467 a ('\n ' * l )
442468 return '' .join (v )
@@ -765,6 +791,7 @@ def main(args=None):
765791 sys .exit (1 )
766792
767793 locale = options .locale , options .encoding
794+ today = datetime .date .today ()
768795
769796 if options .type == "html" :
770797 if options .month :
@@ -781,7 +808,7 @@ def main(args=None):
781808 optdict = dict (encoding = encoding , css = options .css )
782809 write = sys .stdout .buffer .write
783810 if options .year is None :
784- write (cal .formatyearpage (datetime . date . today () .year , ** optdict ))
811+ write (cal .formatyearpage (today .year , ** optdict ))
785812 else :
786813 write (cal .formatyearpage (options .year , ** optdict ))
787814 else :
@@ -797,10 +824,15 @@ def main(args=None):
797824 if options .month is not None :
798825 _validate_month (options .month )
799826 if options .year is None :
800- result = cal .formatyear (datetime .date .today ().year , ** optdict )
827+ optdict ["highlight_day" ] = today
828+ result = cal .formatyear (today .year , ** optdict )
801829 elif options .month is None :
830+ if options .year == today .year :
831+ optdict ["highlight_day" ] = today
802832 result = cal .formatyear (options .year , ** optdict )
803833 else :
834+ if options .year == today .year and options .month == today .month :
835+ optdict ["highlight_day" ] = today
804836 result = cal .formatmonth (options .year , options .month , ** optdict )
805837 write = sys .stdout .write
806838 if options .encoding :
0 commit comments