colorama icon indicating copy to clipboard operation
colorama copied to clipboard

Unexpected background color rendered in terminal

Open RoryLiang opened this issue 2 years ago • 0 comments

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

RoryLiang avatar Apr 28 '22 14:04 RoryLiang