GeezerVison is showing github.com — Highlight today in colour in calendar's CLI output · Issue #128317 · python/cpython
Highlight today in colour in calendar's CLI output #128317DescriptionFeature or enhancement
In Python 3.13 we added colour output to the new REPL, tracebacks and doctest, and in 3.14 to unittest and test.regrtest, which can also be controlled with the PYTHON_COLORS, NO_COLOR and FORCE_COLOR environment variables:
On macOS, the cal utility does something similar, but highlights today.
The calendar module has a CLI to print out a calendar to the terminal, but with no highlighting. Let's add it.
Linked PRs
Reacted by Erlend E. Aasland and Andrew Svetlov Reacted by Petr Viktorin Activityencukou commented on Jan 3, 2025 Thank you!
I hate to spoil the fun, but this breaks non-interactive usage (e.g. ./python -m calendar | less).
IMO, the default should look at sys.stdout.isatty() (not stderr). , and be off for formatweek (edit: oh, it already is). hugovk commented on Jan 4, 2025 Thanks, good idea. Please see PR #128498. encukou commented on Jan 6, 2025 Did you consider putting the feature in a private _CLIDemoCalendar class, which would override formatday?
(As I said I'd hate to spoil the fun. Please do take my opinions just as input for consideration.)
This feature adds some complexity to the API, but doesn't generalize to any other use cases -- for example, highlight weekends/holidays, not just the current day. Or highlight in HTML. Or highlight today in a pure text calendar, for example:
January 2025
Mo Tu We Th Fr Sa Su
1 2 3 4 5
[ 6] 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
calendar has a rather powerful (though perhaps dated) mechanism for configuration: subclassing and overriding methods like formatday. This feature adds an alternate mechanism, and I'm not sure it meshes well with the current API.
joey-cramer commented on Jan 16, 2025 Hi @hugovk,
I hope this is the right place to comment with my idea.
I am interested in if there are any plans or interest in adding week number to the python calendar?
According to this document (https://docs.python.org/3/library/time.html) %V for week is already a defined entity.
ISO 8601 week number (as a decimal number [01,53]). The first week of the year is the one that contains the first Thursday of the year. Weeks start on Monday.
hugovk commented on Jan 16, 2025 ZeroIntensity commented on Jan 28, 2025 Using Hugo's dashboard: is this all done now? hugovk commented on Jan 29, 2025
Using Hugo's dashboard:
🎉
is this all done now?
Thanks for the reminder, not yet: I was planning on giving Petr's suggestion a shot: #128317 (comment).
Did you consider putting the feature in a private _CLIDemoCalendar class, which would override formatday?
I hadn't, something like this? hugovk@8856aeb. It overrides formatday, formatmonth and formatyear.
There's quite a bit of duplication between each class's formatmonth and formatyear. We could deduplicate formatmonth like hugovk@05a5099, and perhaps formatyear like hugovk@738844f, but I'm not sure about those.
What do you think?
(As I said I'd hate to spoil the fun. Please do take my opinions just as input for consideration.)
Thank you, it's very welcome! encukou commented on Jan 31, 2025 Thanks for considering it!
The first commit does seem cleaner to me than putting terminal colours directly in TextCalendar.
Perhaps add an __init__ with self.highlight_day = highlight_day? hugovk commented on Feb 3, 2025 serhiy-storchaka commented on Feb 28, 2025 This change caused a regression. See #130665. Reacted by Hugo van Kemenade
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|