ANSI background doesn't apply until non-space character

I have noticed that the ansii codes are being printed out weird. Look at the picture.

print("\033[43m     f   \033[0m")
# You would instead think that the 7 empty characters + the f are being highlighted
# But the entire line after the f are being colored (including the f), even beyond the \033[0m

What can I do about this or is this a problem for replit?

You can reset the background color to black before you end your print() statement like this:

print("\033[43m     f   \033[30m\033[0m")

Thanks for your responds, but this doesn’t work either.

Sorry for the long response, was trying to find another solution.

You can add \u00a0 after the background color reset:

print("\033[43m     f   \033[40m\u00a0\033[0m")
1 Like

Good solution, but now it prints black high lite, after the origin color
And the behind the f the color is still gone, it should be there.
How could replit mess this ansii printing so up.

I don’t think it’s just Replit alone though…

For the spaces before the f, you can add the same \u00a0 unicode at the start before the spaces but after the first ANSII code.

:x: image

Then I guess it’s just a Replit thing that removes the spaces I guess.

Thank would be unlikely, more likely to be some ascii coding difference somewhere.

1 Like

If you’re searching for Ansii Color Codes, here’s a list:

class Colors:
    PURPLE = "\033[95m"
    CYAN = "\033[96m"
    DARKCYAN = "\033[36m"
    BLUE = "\033[94m"
    GREEN = "\033[92m"
    YELLOW = "\033[93m"
    RED = "\033[91m"
    BOLD = "\033[1m"
    UNDERLINE = "\033[4m"
    END = "\033[0m"

Example Code: