GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-148766: Add colour to Python help by hugovk · Pull Request #148767 · python/cpython Conversation
|
| Before | After |
|---|---|
--help | --help |
|
|
--help-all | --help-all |
|
|
📚 Documentation preview 📚: https://cpython-previews--148767.org.readthedocs.build/
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| #if defined(MS_WINDOWS) && defined(HAVE_WINDOWS_CONSOLE_IO) | ||
| { | ||
| DWORD mode = 0; | ||
| HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); |
There was a problem 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).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Something like 294d008?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PyMem_RawFree(buf); | ||
| } | ||
| else { | ||
| fprintf(f, usage_line, program); |
There was a problem 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This now falls back to no tags.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return; | ||
| } | ||
| } | ||
| fprint_tagged(stdout, usage_envvars, 0); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We still need formatting here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated to use colour if available.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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}?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the reviews, any further comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Would something like this be more maintainable? #define RESET "\x1b[0m" #define ENVVAR(STR) "\x1b[1;36m" STR RESET |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nice idea, updated :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Documentation build overview
5 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This version is barely readable. What if return to the previous version with substitutions and use some of substitution codes to substitute the program name, the default PYTHONHOME, the path separator instead of just color sequences? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| SHORTOPT("-d") " : turn on parser debugging output (for experts only, only works on\n" | ||
| " debug builds); also " ENVVAR_REF("PYTHONDEBUG") SUMMARY_LABEL("=x") "\n" | ||
| SHORTOPT("-E") " : ignore " ENVVAR_REF("PYTHON*") " environment variables (such as " ENVVAR_REF("PYTHONPATH") ")\n" | ||
| SHORTOPT("-h") " : print this help message and exit (also " SHORTOPT_SUMMARY("-?") " or " ENVVAR_REF("--help") ")\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| SHORTOPT("-h") " : print this help message and exit (also " SHORTOPT_SUMMARY("-?") " or " ENVVAR_REF("--help") ")\n" | |
| SHORTOPT("-h") " : print this help message and exit (also " SHORTOPT_SUMMARY("-?") " or " LONGOPT("--help") ")\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| " this option has no effect on stdin; also " ENVVAR_REF("PYTHONUNBUFFERED") SUMMARY_LABEL("=x") "\n" | ||
| SHORTOPT("-v") " : verbose (trace import statements); also " ENVVAR_REF("PYTHONVERBOSE") SUMMARY_LABEL("=x") "\n" | ||
| " can be supplied multiple times to increase verbosity\n" | ||
| SHORTOPT("-V") " : print the Python version number and exit (also " ENVVAR_REF("--version") ")\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| SHORTOPT("-V") " : print the Python version number and exit (also " ENVVAR_REF("--version") ")\n" | |
| SHORTOPT("-V") " : print the Python version number and exit (also " LONGOPT("--version") ")\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "PYTHON_FROZEN_MODULES: whether to use frozen modules; the default is \"on\"\n" | ||
| " for installed Python and \"off\" for a local build\n" | ||
| " (-X frozen_modules)\n" | ||
| HEADING("These variables have equivalent command-line options (see ") ENVVAR_REF("--help") " for details):" "\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| HEADING("These variables have equivalent command-line options (see ") ENVVAR_REF("--help") " for details):" "\n" | |
| HEADING("These variables have equivalent command-line options") "(see " ENVVAR_REF("--help") " for details):" "\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "PYTHONPERFSUPPORT: support the Linux \"perf\" profiler (-X perf)\n" | ||
| ENVVAR("PYTHONINSPECT") " : inspect interactively after running script (" SHORTOPT_SUMMARY("-i") ")\n" | ||
| ENVVAR("PYTHONINTMAXSTRDIGITS") ": limit the size of int<->str conversions;\n" | ||
| " 0 disables the limit (" SHORTOPT_SUMMARY("-X") " " ENVVAR_REF("int_max_str_digits") SUMMARY_LABEL("=N") ")\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| " 0 disables the limit (" SHORTOPT_SUMMARY("-X") " " ENVVAR_REF("int_max_str_digits") SUMMARY_LABEL("=N") ")\n" | |
| " " SUMMARY_LABEL("0") " disables the limit (" SHORTOPT_SUMMARY("-X") " " ENVVAR_REF("int_max_str_digits") SUMMARY_LABEL("=N") ")\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ENVVAR("PYTHONEXECUTABLE") ": set sys.argv[0] to this value (macOS only)\n" | ||
| #endif | ||
| "PYTHONHASHSEED : if this variable is set to 'random', a random value is used\n" | ||
| ENVVAR("PYTHONHASHSEED") " : if this variable is set to 'random', a random value is used\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ENVVAR("PYTHONHASHSEED") " : if this variable is set to 'random', a random value is used\n" | |
| ENVVAR("PYTHONHASHSEED") " : if this variable is set to '" SUMMARY_LABEL("random") "', a random value is used\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "PYTHONMALLOCSTATS: print memory allocator statistics\n" | ||
| "PYTHONPATH : '%lc'-separated list of directories prefixed to the\n" | ||
| ENVVAR("PYTHONMALLOCSTATS") ": print memory allocator statistics\n" | ||
| ENVVAR("PYTHONPATH") " : '%lc'-separated list of directories prefixed to the\n" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ENVVAR("PYTHONPATH") " : '%lc'-separated list of directories prefixed to the\n" | |
| ENVVAR("PYTHONPATH") " : '" SUMMARY_LABEL(%lc) "'-separated list of directories prefixed to the\n" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
My previous comment was related to the version prior to the latest change, but I still thing that substitution-based approach would be clearer than macros-based. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka Could you give a short example of what you're thinking of? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Simple example: "{E}PYTHONHOME{r} : alternate <prefix> directory (or <prefix>{b}{D}{r}<exec_prefix>).\n" " The default module search path uses {b}{H}{r}.\n"
To avoid repeated "#E{PYTHONHOME} : alternate <prefix> directory (or <prefix>#b{#D}<exec_prefix>).\n" " The default module search path uses #b{#H}.\n" This is simpler than it looks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks, updated! How does this look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks all for the reviews! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.