When running python scripts or programs built using python, errors are emitted in dark red. As I get older, this is getting harder for me to read, to the point I have to squint, magnify, or fuss with the console properties and re-run commands.
I really dont want to change the console defaults because other programs generally dont have this problem, and it just seems to be Python that doesn't honor the hosting console's color settings. I also dont know ahead of time which programs may have been built with python (Azure CLI for example) to set the colors ahead of time.
Is there a way to change the DarkRed that python wants to use for errors to a color that is easier to distinguish, like "regular" Red? For any py script or program that runs on my machine?
EDIT: Here is an example of invoking a program written using Python and the dark red. My py scripts library is on my work computer.
EDIT2: Its pip that was the other thing that uses the dark red.
What is an error color? Error color indicates errors in components, such as invalid text in a text field. The baseline error color is #B00020.
To add color and style to text, you should create a class called ANSI, and inside this class, declare the configurations about the text and color with code ANSI. Functions Used: background: allows background formatting. Accepts ANSI codes between 40 and 47, 100 and 107.
First, python
is innocent. The culprit is azure-cli
itself. It uses a lib named knack
for configuring logging
. And knack
uses colorama
to configure colored output.
But the problem is, the RED
in colorama
is \033[31m
. Which is what you see, somehow like dim red.
So the solution is simple, we manually modify that knack
package.
Suppose your azure-cli
is installed at C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2
.
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages
, delete that knack
directory or rename it.class _CustomStreamHandler(logging.StreamHandler):
COLOR_MAP = None
@classmethod
def get_color_wrapper(cls, level):
if not cls.COLOR_MAP:
import colorama
def _color_wrapper(color_marker):
def wrap_msg_with_color(msg):
return '{}{}{}'.format(color_marker, msg, colorama.Style.RESET_ALL)
return wrap_msg_with_color
colorama.Fore.RED = "\033[31;1m" # <- add this line
cls.COLOR_MAP = {
logging.CRITICAL: _color_wrapper(colorama.Fore.RED),
logging.ERROR: _color_wrapper(colorama.Fore.RED),
logging.WARNING: _color_wrapper(colorama.Fore.YELLOW),
logging.INFO: _color_wrapper(colorama.Fore.GREEN),
logging.DEBUG: _color_wrapper(colorama.Fore.CYAN)
}
return cls.COLOR_MAP.get(level, None)
...
For pip specifically, there is a "--no-color" command line option: https://pip.pypa.io/en/stable/reference/pip/#general-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With