GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #128317

New issue
Copy link
New issue
Copy link
Closed
Closed
Highlight today in colour in calendar's CLI output#128317
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@hugovk
hugovk
opened on Dec 28, 2024
Issue body actions

Feature 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:

  • https://docs.python.org/3.14/whatsnew/3.14.html#unittest
  • https://docs.python.org/3.14/using/cmdline.html#using-on-controlling-color

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

  • gh-128317: Highlight today in colour in calendar CLI output #128318
  • gh-128317: Document calendar.TextCalendar.formatweek #128353
  • [3.13] gh-128317: Document calendar.TextCalendar.formatweek (GH-128353) #128357
  • [3.12] gh-128317: Document calendar.TextCalendar.formatweek (GH-128353) #128358
  • gh-128317: Move CLI calendar highlighting to private class #129625
Reacted by Erlend E. Aasland and Andrew Svetlov
Reacted by Petr Viktorin

Activity

  1. hugovk
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Dec 28, 2024
  2. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Dec 28, 2024
  3. hugovk
    added a commit that references this issue on Dec 30, 2024

    gh-128317: Document `calendar.TextCalendar.formatweek` (#128353)

    6dbace3
  4. miss-islington
    added 2 commits that reference this issue on Dec 30, 2024

    pythongh-128317: Document `calendar.TextCalendar.formatweek` (pythonG…

    405bc72

    pythongh-128317: Document `calendar.TextCalendar.formatweek` (pythonG…

    7fc308a
  5. hugovk
    added 3 commits that reference this issue on Dec 30, 2024

    [3.13] gh-128317: Document `calendar.TextCalendar.formatweek` (GH-128353

    207a81a

    [3.12] gh-128317: Document `calendar.TextCalendar.formatweek` (GH-128353

    b22d0fc

    gh-128317: Highlight today in colour in calendar CLI output (#128318)

    f21af18
  6. hugovk
    closed this as completedon Jan 3, 2025
  7. encukou commented on Jan 3, 2025

    @encukou
    encukou
    on Jan 3, 2025
    Member
    More actions

    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).

  8. encukou
    reopened this on Jan 3, 2025
  9. WolframAlph
    added a commit that references this issue on Jan 4, 2025

    pythongh-128317: Highlight today in colour in calendar CLI output (py…

    49140ab
  10. hugovk commented on Jan 4, 2025

    @hugovk
    hugovk
    on Jan 4, 2025
    MemberAuthor
    More actions

    Thanks, good idea. Please see PR #128498.

  11. encukou commented on Jan 6, 2025

    @encukou
    encukou
    on Jan 6, 2025
    Member
    More actions

    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.

  12. srinivasreddy
    added 2 commits that reference this issue on Jan 8, 2025

    pythongh-128317: Document `calendar.TextCalendar.formatweek` (python#…

    d665607

    pythongh-128317: Highlight today in colour in calendar CLI output (py…

    bf9975c
  13. joey-cramer commented on Jan 16, 2025

    @joey-cramer
    joey-cramer
    on Jan 16, 2025
    More actions

    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.

  14. hugovk commented on Jan 16, 2025

    @hugovk
    hugovk
    on Jan 16, 2025
    MemberAuthor
    More actions

    Hello! I think it could be useful. There's some potential complexity as some countries decide which is week 1 differently, but if we can follow ISO 8601 that would simplify things.

    The calendar module docs (https://docs.python.org/3/library/calendar.html) says ISO 8601 is used for other calculations:

    Zero and negative years are interpreted as prescribed by the ISO 8601 standard.

    The calendar module also allows you to define set a different weekday as the first one od the week, we'd need to check how that affects things.

    https://docs.python.org/3/library/calendar.html#calendar.setfirstweekday

    Please could you post a proposal to the ideas forum?

    https://discuss.python.org/c/ideas/6

    Thanks!

  15. ZeroIntensity commented on Jan 28, 2025

    @ZeroIntensity
    ZeroIntensity
    on Jan 28, 2025
    Member
    More actions

    Using Hugo's dashboard: is this all done now?

  16. hugovk commented on Jan 29, 2025

    @hugovk
    hugovk
    on Jan 29, 2025
    MemberAuthor
    More actions

    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!

    Reacted by Petr Viktorin
  17. encukou commented on Jan 31, 2025

    @encukou
    encukou
    on Jan 31, 2025
    Member
    More actions

    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?

  18. hugovk commented on Feb 3, 2025

    @hugovk
    hugovk
    on Feb 3, 2025
    MemberAuthor
    More actions

    Good idea, please see PR #129625.

  19. hugovk
    added a commit that references this issue on Feb 8, 2025

    gh-128317: Move CLI calendar highlighting to private class (#129625)

    1bccd6c
  20. hugovk
    closed this as completedon Feb 9, 2025
  21. serhiy-storchaka commented on Feb 28, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Feb 28, 2025
    Member
    More actions

    This change caused a regression. See #130665.

    Reacted by Hugo van Kemenade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.