Colored console messages (ANSI escape codes)

I was wondering if I could color console messages using ANSI escape codes.
I’ve tried the following code but it didn’t work properly:

 constexpr char RED[] = "ESC[48;5;{196}m";
std::cout << RED << "this text should be red \n";

But it just returns ESC[48;5;{196}mthis text should be red
Does anyone have experience on this or know how do do it?

I can’t test right now to see if it’ll do what you expect (that’s up to the terminal emulator you’re using, so the driver station), but your ESC should probably be \e or \033 - Assuming you’re looking at wiki pages or similar, they mean ESC as in the literal escape character code.

1 Like

I’ll try doing that later today. I’ll update you on my progress

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.