Reputation: 13
Heres a picture of the output (left is .exe, right is Visual Studio.]
I'm trying to make a tic-tac-toe program, and when I run it in Visual Studio it displays fine and there are no bugs. However when I try to run the .exe file that was made from the VS compiler, rather than
colored X's and O's it just displays the ansi color code that it would be. Does anyone know how I would fix this, or what the cause could be?
Here's how I'm defining the colors:
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
Here's an example of one of my printf calls:
printf(ANSI_COLOR_RED"\nYOU LOST. BETTER LUCK NEXT TIME...\n\n");
printf(ANSI_COLOR_RESET);
Upvotes: 1
Views: 1136
Reputation: 13
I was able to get it working by adding the ansi_escapes.h and ansi_escapes.c files from this website into my visual studio project and then rebuilding the program. here's the website with the files
Upvotes: 0
Reputation: 193
The color escape codes are interpreted by your terminal. That's the place to look for fixes to this problem. Here is an overview of ansi color code usage in Windows, and it seems like it should work, but needs some fixes on older versions:
Enabling ANSI colors in older versions of Windows To use ANSI colours in the Windows terminal requires setting VirtualTerminalLevel. VirtualTerminalLevel = 1 is now set by default for the terminal and in ConPTY. In Windows versions 1511 through to 1903 this had to be enabled in the registry at:
[HKEY_CURRENT_USER\Console] "VirtualTerminalLevel"=dword:00000001
Alternatively it can be enabled by calling the SetConsoleMode API with the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.
Upvotes: 1