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.
Why doesn't click.echo
function show me selected color?
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, andclick
delete ANSI codes.