Skip to content

New COLORIZED REPL nearly unusable on MS-Windows 10 by default #125609

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

Open
NoelJB opened this issue Oct 16, 2024 · 8 comments
Open

New COLORIZED REPL nearly unusable on MS-Windows 10 by default #125609

NoelJB opened this issue Oct 16, 2024 · 8 comments
Labels
OS-windows stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@NoelJB
Copy link

NoelJB commented Oct 16, 2024

Bug report

Bug description:

The new colorized REPL is nearly unusable on MS-Windows 10 with the default colors it is using. I usually work on Linux, but haven't tested there as yet.

Here are three files:

  • one shows the colorized output of a traceback in CMD.EXE. It is much more readable in the photo than on the screen.
    cmd-colorized
  • The second one shows the impact of PYTHON_COLORS=0, which makes it usable again.
    cmd-no-color
  • one shows the even worse impact in PowerShell, where it is completely unreadable, although you can prove that the text is there by copying from the screen and pasting into an editor.
    powershell-colorized

There are no docs on how to even go about adjusting the colors that are being selected by the new REPL for any platform.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

@NoelJB NoelJB added the type-bug An unexpected behavior, bug, or error label Oct 16, 2024
@hugovk hugovk added OS-windows topic-repl Related to the interactive shell labels Oct 16, 2024
@hugovk
Copy link
Member

hugovk commented Oct 16, 2024

There's currently no way to adjust the colours, but I believe this might be coming for 3.14.

As you've noted, you can use PYTHON_COLORS=0 to disable the colours, or you can use NO_COLOR=1 or TERM=dumb. These are documented at:

https://docs.python.org/3/using/cmdline.html#controlling-color

@terryjreedy
Copy link
Member

To me, the cmd.exe traceback output on a real screen, not the photo, is readable enough. For background, I prefer the dark blue preset (0,0,128) to black, because the white/black contrast is overly intense. What do you have a problem with?

@NoelJB
Copy link
Author

NoelJB commented Oct 17, 2024

Personally, I have an issue with the dim purple on black. As did an entire class of students, so not just my eyes and/or monitor.

@evle-zzz
Copy link

Same here, unreadable even with default settings, and forcing people to change the terminal settings just to make Python REPL readable is not a viable option. That makes whole feature useless.
Also, why would there be an "OS-windows" tag here? I don't see any configuration for linux either.

@NoelJB
Copy link
Author

NoelJB commented Oct 18, 2024

@evle-zzz, the OS-Windows tag is probably because I posted screen captures for MS-Windows and had not been able to test on Linux at the time. Can you post some pictures from Linux?

It would be nice if PYTHON_COLORS worked along similar lines to LS_COLORS, but with a better syntax, perhaps allowing either individual settings or a theme name.

[Note to self and anyone else thinking of contributing code, this links to the original submission]

@arcmags
Copy link

arcmags commented Dec 22, 2024

This is an accessibility issue. Regardless of personal preference, readability, or operating system, these colors should really be customizable to accommodate color blindness.

For a hacky workaround, put a usercustomize.py in your pythonpath with something like:

import _colorize
_colorize.ANSIColors.MAGENTA = '\x1b[0;38;5;13m'
# ...other changes...

@PennRobotics
Copy link

PennRobotics commented Feb 7, 2025

Two details about usercustomize.py:

  1. pythonpath is found via import sys; sys.path and can be expanded using the env var PYTHONPATH
  2. In a virtual environment, ENABLE_USER_SITE might be False unless you also (in the case of the venv module) use --system-site-packages. You can see how this variable is set using python -m site

The color class is listed below. Traceback uses both magentas and both reds.

class ANSIColors:
    BACKGROUND_YELLOW = "\x1b[43m"
    BOLD_GREEN = "\x1b[1;32m"
    BOLD_MAGENTA = "\x1b[1;35m"
    BOLD_RED = "\x1b[1;31m"
    BLACK = "\x1b[30m"
    GREEN = "\x1b[32m"
    GREY = "\x1b[90m"
    MAGENTA = "\x1b[35m"
    RED = "\x1b[31m"
    RESET = "\x1b[0m"
    YELLOW = "\x1b[33m"

Many terminals support at least 256 color ANSI escape codes, and the true color format is ESC[38;2;<r>;<g>;<b>m (decimal digits; not hex)

@cool-RR
Copy link
Contributor

cool-RR commented Apr 4, 2025

Until someone implements a theme system for Python, here is a workaround: unfuck_python_colors.py. You may run it in any virtualenv to create a sitecustomize.py file there that hacks these colors to be reasonable.

@picnixz picnixz added the stdlib Python modules in the Lib dir label Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

8 participants