@@ -686,28 +686,61 @@ def __init__(self, highlight_day=None, *args, **kwargs):
686686 super ().__init__ (* args , ** kwargs )
687687 self .highlight_day = highlight_day
688688
689- def formatweek (self , theweek , width , * , highlight_day = None ):
689+ def _get_theme (self ):
690+ from _colorize import get_theme
691+
692+ return get_theme (tty_file = sys .stdout )
693+
694+ def formatday (self , day , weekday , width , * , highlight_day = None ):
690695 """
691- Returns a single week in a string (no newline) .
696+ Returns a formatted day .
692697 """
693- if highlight_day :
694- from _colorize import get_colors
695-
696- ansi = get_colors ()
697- highlight = f"{ ansi .BLACK } { ansi .BACKGROUND_YELLOW } "
698- reset = ansi .RESET
698+ if day == 0 :
699+ s = ''
699700 else :
700- highlight = reset = ""
701+ s = f'{ day :2} '
702+ s = s .center (width )
703+ if day == highlight_day :
704+ theme = self ._get_theme ().calendar
705+ s = f"{ theme .highlight } { s } { theme .reset } "
706+ return s
701707
708+ def formatweek (self , theweek , width , * , highlight_day = None ):
709+ """
710+ Returns a single week in a string (no newline).
711+ """
702712 return ' ' .join (
703- (
704- f"{ highlight } { self .formatday (d , wd , width )} { reset } "
705- if d == highlight_day
706- else self .formatday (d , wd , width )
707- )
713+ self .formatday (d , wd , width , highlight_day = highlight_day )
708714 for (d , wd ) in theweek
709715 )
710716
717+ def formatweekheader (self , width ):
718+ """
719+ Return a header for a week.
720+ """
721+ header = super ().formatweekheader (width )
722+ theme = self ._get_theme ().calendar
723+ return f"{ theme .weekday_header } { header } { theme .reset } "
724+
725+ def formatmonthname (self , theyear , themonth , width , withyear = True ):
726+ """
727+ Return a formatted month name.
728+ """
729+ name = super ().formatmonthname (theyear , themonth , width , withyear )
730+ theme = self ._get_theme ().calendar
731+ if (
732+ self .highlight_day
733+ and self .highlight_day .year == theyear
734+ and self .highlight_day .month == themonth
735+ ):
736+ color = theme .highlight
737+ name_only = name .strip ()
738+ colored_name = f"{ color } { name_only } { theme .reset } "
739+ return name .replace (name_only , colored_name , 1 )
740+ else :
741+ color = theme .month_name
742+ return f"{ color } { name } { theme .reset } "
743+
711744 def formatmonth (self , theyear , themonth , w = 0 , l = 0 ):
712745 """
713746 Return a month's calendar string (multi-line).
0 commit comments