Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Typer.style fails in Windows Powershell with colorama installed #84

Closed
Fronkan opened this issue Apr 2, 2020 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@Fronkan
Copy link

Fronkan commented Apr 2, 2020

Describe the bug

I tried to print red text in powershell on Windows. However, it just printed with escape symbols instead. This is with colorama installed and if i manually initialize colorama the colors works as it should.

To Reproduce

Reporduce non-working version:

import typer
def main():
    print(typer.style("RED", fg=typer.colors.RED))
if __name__ == "__main__":
    typer.run(main)

Outputs:

�[31mRED�[0m

With manual colorma init:

import typer
import colorama
colorama.init()
def main():
    print(typer.style("RED", fg=typer.colors.RED))
if __name__ == "__main__":
    typer.run(main)

Ouputs, in red text:

RED

Expected behavior

As it in the documentation, https://typer.tiangolo.com/tutorial/printing/#color, is stated that you don't have to manually initialize colorama I expected the first to work.

Environment

  • OS: Windows
  • Typer Version: 0.1.1
  • Python version: 3.7.2
@tiangolo
Copy link
Member

So, for all the Colorama Windows magic to work you have to use typer.echo() instead of print(), like:

import typer
def main():
    typer.echo(typer.style("RED", fg=typer.colors.RED))
if __name__ == "__main__":
    typer.run(main)

@Fronkan
Copy link
Author

Fronkan commented Apr 18, 2020

Thank you! I must haves missed this.

@Fronkan Fronkan closed this as completed Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants