question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] color codes in windows console

See original GitHub issue

Describe the bug

Color/format codes in console are literally printed.

To Reproduce

Use a simple fastapi setup like your readme example.

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}

Expected behavior

I figured out that this can be fixed by using os.system("cls") on top of your main.py

Screenshots

grafik

Expected with os.system("cls"):

grafik

Environment

  • OS: Windows 10
  • FastAPI Version 0.45.0
  • Python version 3.8

Additional context

I do not think adding a raw os.system("cls") should be the right solution for a library. However, I do not know another way to fix the issue. On Ubuntu18.04 everything works as expected. Could be a problem with my windows machine. If this is a problem with my local machine, I am sorry. Also I know that I should post this on the uvicorn repo instead. But I figured that you should mention this as long as the bug exists.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Jarmos-sancommented, Dec 12, 2020

This is a fairly common bug with non-ANSI-aware terminal(s). There’re similar reports even with Poetry (check this thread #1887 & if you search enough you might come across many other like these).

And also, to be honest it definitely isn’t a FastAPI related issue either. Not to forget how trivial & non-blocking this issue is. And if the guys at uvicorn are inclined they might want to look into this issue. With that in mind, I think it’s safe to close the issue.

Developing on Windows has never been better. You got WSL, Windows Terminal & many other CLI stuff to use. Take a look at the screenshot below, it’s a breeze working with the new Windows Terminal & it’s only gettting over time.

image

So my suggestions?

You don’t have to migrate to a Unix environment just for a “good” CLI. Windows 10 is fine, just use Powershell (or WSL) with the new Windows Terminal, more so if you’re a developer. This opinion is from someone who uses Ubuntu while on-the-go & Windows 10 on a desktop environment.

1reaction
zaanposnicommented, Apr 13, 2020

Hello @tiangolo,

I also grew up a bit and now use Linux for development 😄. However, I wanted to report this problem because it still exists. I’ve learned my part and think that using cmd.exe shouldn’t support everyone in their library.

How should we proceed? The problem still persists, although I would never expect anyone to fix it as it is very banal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Put Color on Windows Console - CodeProject
In this article, you will see how to use ANSI colors in Windows and Linux without any modification on code, with Python, C,...
Read more >
bug #62575: Garbled ANSI color codes in Cygwin mintty
bug #62575: Garbled ANSI color codes in Cygwin mintty ; Severity: 3 - Normal, Item Group: None ; Status: None, Privacy: Public ;...
Read more >
How to echo with different colors in the Windows command line
I wanted to to print one single line in a different color. Use ANSI Escape Sequences. Windows before 10 - no native support...
Read more >
Standard for ANSI Colors in Terminals
The current situation to get colored output from most console commands is a mess. Some check for the TERM environment variable, or look...
Read more >
Use ANSI colors in the terminal - Windows CMD - SS64.com
Specify the color codes in a batch file by ECHOing the foreground and/or background color codes (from the following table) followed by the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found