Skip to content

gh-148766: Add colour to Python help#148767

Draft
hugovk wants to merge 3 commits intopython:mainfrom
hugovk:3.15-help-colour
Draft

gh-148766: Add colour to Python help#148767
hugovk wants to merge 3 commits intopython:mainfrom
hugovk:3.15-help-colour

Conversation

@hugovk
Copy link
Copy Markdown
Member

@hugovk hugovk commented Apr 19, 2026

python --help (and especially --help-all) is a monochrome wall of text. Similar to argparse help, let's add some colour to add structure and improve readability.

Here's real screenshots of --help and termshot capture of --help-all:

Before After
--help
--help
--help-all
--help-all

📚 Documentation preview 📚: https://cpython-previews--148767.org.readthedocs.build/

@hugovk hugovk added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 19, 2026
Comment thread Python/initconfig.c Outdated
Comment thread Python/initconfig.c Outdated
#if defined(MS_WINDOWS) && defined(HAVE_WINDOWS_CONSOLE_IO)
{
DWORD mode = 0;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also consider stderr (or maybe it does? I don't know Windows quirks).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like 294d008?

Comment thread Python/initconfig.c Outdated
PyMem_RawFree(buf);
}
else {
fprintf(f, usage_line, program);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If PyMem_RawMalloc fails we will get the raw tags, no?

Comment thread Python/initconfig.c Outdated
return;
}
}
fprint_tagged(stdout, usage_envvars, 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need formatting here?

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the program path by accident contains {E}?

@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented Apr 21, 2026

Updated to flip it: colour codes are now included in the help text (via macros to keep it tidier), and stripped out when not needed.

So {E} in the path is not an issue.

@hugovk hugovk marked this pull request as draft April 21, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants