tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.51k stars 249 forks source link

Unexpected background color rendered in terminal #343

Open RoryLiang opened 2 years ago

RoryLiang commented 2 years ago
import colorama
from contextlib import contextmanager

b = "type: <\x1b[39m\x1b[38;5;100mclass\x1b[39m\x1b[38;5;245m \x1b[39m\x1b[38;5;166m'\x1b[39m\x1b[38;5;32mdict\x1b[39m\x1b[38;5;36m'\x1b[39m\x1b[38;5;36m>\x1b[39m"

@contextmanager
def supportTerminalColorsInWindows():
    colorama.init()
    yield
    colorama.deinit()

print(b)

with supportTerminalColorsInWindows():
    print(b)

Running the above code gives an unexpected result shown below on both PowerShell and CMD.

image image