Python click module. Show color in windows and mac

369 Views Asked by At

I need to show messages with color in MacOS and in Windows terminal. I used click, and tried that code:

def print_error(
        message,  # type: str
):  # type: (...) -> None
    error_word = click.style('ERROR: ', fg='red')
    click.echo(error_word + click.style(message, bg=bg, bold=bold, underline=underline, blink=blink), err=True)

But I got white text on MacOS, not red. If I change click.echo to print, everything will be great. But I don't think that it is a good idea.

First one is a click.echo, second one - print

Why doesn't click.echo function show me selected color?

1

There are 1 best solutions below

0
On BEST ANSWER

I found the main problem. I ran python script, using cmake. When I ran it through cmake, python don't have any tty now, and function isatty() will return False. In that library, it means that it is a file, and click delete ANSI codes.