Skip to content

Add colour to pprint output #145217

Description

@hugovk

Feature or enhancement

Proposal:

We can use the existing syntax theme to add colour to the output of:

  • pprint.pp(data)
  • pprint.pprint(data)
  • pprint.PrettyPrinter().pprint(data)

cpython/Lib/_colorize.py

Lines 312 to 323 in 9b22261

classSyntax(ThemeSection):
prompt: str=ANSIColors.BOLD_MAGENTA
keyword: str=ANSIColors.BOLD_BLUE
keyword_constant: str=ANSIColors.BOLD_BLUE
builtin: str=ANSIColors.CYAN
comment: str=ANSIColors.RED
string: str=ANSIColors.GREEN
number: str=ANSIColors.YELLOW
op: str=ANSIColors.RESET
definition: str=ANSIColors.BOLD
soft_keyword: str=ANSIColors.BOLD_BLUE
reset: str=ANSIColors.RESET

As usual, this will respect the environment variables to control colour and the output stream's capabilities.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions