-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Add colour to argparse
help
#130645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think this should be done. |
Image links don't work in the survey. I'd vote for REPL style. It's not bombarding you with color and the magenta/purple is generally visible in all terminal styles. Raymond could you please clarify why? We already have some color in the REPL and there are ongoing efforts to add more (#130472) so it seems people are generally in favor of color. Edit: Seeing it now, I think the simple ruff style would be fine, what do you think @rhettinger, about a very simple coloring? |
Thanks, fixed. |
Are you aware of the |
I think that adding an option (which is off by default) is a good idea, but |
If you end-up doing this over my objections (no major standard command-line tool does this), then it must be opt-in. Also, the bulk of the code should be in a separate submodule that is only imported with needed. Start-up time is a critical issue for argparse. We've worked hard to avoid dependencies and to have a fast load time. Also, the choice of colors really matters. Bad choices can impair usability for all users, or for users with the particular choice of light or dark backgrounds, or for users with vision issues including various kinds of color blindness. IPython is an example of a tool that made poor choices. When running AFACIT, no group of users has ever requested this feature even though this is a heavy used, popular module. ISTM that the OP is doing this as part of a "sweep" across modules (such as unittest) without considering the whether the existing users of the module want or need this. |
I wasn't, thanks for sharing. I think this would still be useful in the stdlib, for when you want to keep your dependencies to a minimum, and rich (plus its dependencies) is a fairly large package.
Yes, it can be opt-in. And the existing
Agreed, this is important.
Absolutely, colour choice and accessibility is important. This is why I've surveyed popular existing tools and picked colours with good contrast, and none of those or my suggestsions use that blue. And @ambv is adding theming support this month, see: #130472 (comment).
Here's some people wanting colour help in argparse:
I think the use of colour in third-party CLI replacements and rich-argparse also points to a demand.
Yes, now that we added colour support in 3.13 for the REPL and tracebacks, I'm looking to see where else we can improve the experience over plain monochrome output. Colour can be extremely helpful. unittest is a great example: coloured pytest output has long been very useful for finding the error(s) in long test logs. And it's now much easier to find errors in our own CI logs since unittest and test.regrtest have colour output.
This is a good example of poor colour choice, thanks. This blue won't be used. As it happens, IPython 9.0.0 was released on Friday with much improved colours! ![]() |
I'm +1 on this, if it's opt-in and ensures that we can ensure the startup time isn't impacted. In CLI tools that I've worked on in the past, we leaned heavily on the ANSI defined color presets when trying to guarantee accessibility/sufficient contrast. |
Feature or enhancement
In Python 3.13 we added colour output to the new REPL,
traceback
anddoctest
, and in 3.14 tounittest
,test.regrtest
andcalendar
, that can also be controlled with thePYTHON_COLORS
,NO_COLOR
andFORCE_COLOR
environment variables:Let's add colour to
argparse
help output.Survey
First, here's a survey of some other CLIs that use colour:
Survey
See also: bat, hyperfine, oxipng, zizmor
These fall into four groups:
Prototypes
I've made prototypes of two of these (uv/cargo style, typer/rich-cli style), and another with blue + magenta similar to the 3.13 REPL/traceback.
Prototypes
I think I prefer the typer/rich-cli style: the extra colour makes it easier to pick out the (green) short options from the (cyan) long options, and from their (green) arguments. And it should also be somewhat familiar to Python users who have used typer-based CLIs.
Linked PRs
argparse
helpΒ #132323The text was updated successfully, but these errors were encountered: