'Why does system color command trigger ANSI escape sequences on Windows?

To display styled text in the console on Windows, I use escape sequences.

print("\x1b[4m" "Underlined Text" "\x1b[0m" "\n")

When I just print out this text, the text in console looks something like this:

←[4mUnderlined text←[0m

But when I execute system color before:

system("color")
print("\x1b[4m" "Underlined Text" "\x1b[0m" "\n")

The text becomes underlined upon execution.

So, what is the system color doing to enable ANSI escape sequences?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source