@@ -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 } { 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 .header
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).
@@ -742,7 +775,9 @@ def formatyear(self, theyear, w=2, l=1, c=6, m=3):
742775 colwidth = (w + 1 ) * 7 - 1
743776 v = []
744777 a = v .append
745- a (repr (theyear ).center (colwidth * m + c * (m - 1 )).rstrip ())
778+ theme = self ._get_theme ().calendar
779+ year = repr (theyear ).center (colwidth * m + c * (m - 1 )).rstrip ()
780+ a (f"{ theme .header } { year } { theme .reset } " )
746781 a ('\n ' * l )
747782 header = self .formatweekheader (w )
748783 for (i , row ) in enumerate (self .yeardays2calendar (theyear , m )):
@@ -843,28 +878,30 @@ def timegm(tuple):
843878
844879def main (args = None ):
845880 import argparse
846- parser = argparse .ArgumentParser (color = True )
881+ parser = argparse .ArgumentParser (
882+ formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
883+ )
847884 textgroup = parser .add_argument_group ('text only arguments' )
848885 htmlgroup = parser .add_argument_group ('html only arguments' )
849886 textgroup .add_argument (
850887 "-w" , "--width" ,
851888 type = int , default = 2 ,
852- help = "width of date column (default 2) "
889+ help = "width of date column"
853890 )
854891 textgroup .add_argument (
855892 "-l" , "--lines" ,
856893 type = int , default = 1 ,
857- help = "number of lines for each week (default 1) "
894+ help = "number of lines for each week"
858895 )
859896 textgroup .add_argument (
860897 "-s" , "--spacing" ,
861898 type = int , default = 6 ,
862- help = "spacing between months (default 6) "
899+ help = "spacing between months"
863900 )
864901 textgroup .add_argument (
865902 "-m" , "--months" ,
866903 type = int , default = 3 ,
867- help = "months per row (default 3) "
904+ help = "months per row"
868905 )
869906 htmlgroup .add_argument (
870907 "-c" , "--css" ,
@@ -879,7 +916,7 @@ def main(args=None):
879916 parser .add_argument (
880917 "-e" , "--encoding" ,
881918 default = None ,
882- help = "encoding to use for output (default utf-8) "
919+ help = "encoding to use for output"
883920 )
884921 parser .add_argument (
885922 "-t" , "--type" ,
@@ -890,7 +927,7 @@ def main(args=None):
890927 parser .add_argument (
891928 "-f" , "--first-weekday" ,
892929 type = int , default = 0 ,
893- help = "weekday (0 is Monday, 6 is Sunday) to start each week (default 0) "
930+ help = "weekday (0 is Monday, 6 is Sunday) to start each week"
894931 )
895932 parser .add_argument (
896933 "year" ,
0 commit comments