Skip to content

click.echo does not force colors on Windows with color=True #2606

@krisztianloki

Description

@krisztianloki

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy