Using click.echo(click.style("Foo", fg="red"), color=True) on Windows will not print "Foo" in red if the output is not a terminal that supports colors, so it seems that color=True is ignored on Windows.
Here is an example code to reproduce the bug:
import click
def main():
test_txt = "click_echo.txt"
with open(test_txt, "w") as f:
click.secho("Without setting color", file=f, fg="red")
click.secho("With color=False", file=f, fg="red", color=False)
click.secho("With color=True", file=f, fg="red", color=True)
click.echo(f"Check the contents of {test_txt}")
if __name__ == "__main__":
main()
After running it on Linux the third line of click_echo.txt will contain the ANSI color codes but on Windows all three lines will be the same (the behavior is the same if echo prints on the console and the script output is redirected to a file)
Environment:
- Python version: 3.9
- Click version: 8.1.7
Using
click.echo(click.style("Foo", fg="red"), color=True)on Windows will not print "Foo" in red if the output is not a terminal that supports colors, so it seems thatcolor=Trueis ignored on Windows.Here is an example code to reproduce the bug:
After running it on Linux the third line of
click_echo.txtwill contain the ANSI color codes but on Windows all three lines will be the same (the behavior is the same ifechoprints on the console and the script output is redirected to a file)Environment: