ANSI Control Code on Windows Console Project

CodeLite installation/troubleshooting forum
HJarausch
CodeLite Veteran
Posts: 98
Joined: Thu Feb 18, 2010 10:54 pm
Genuine User: Yes
IDE Question: C++
Contact:

ANSI Control Code on Windows Console Project

Post by HJarausch »

Hi,

the following example runs fine in a Console Project on Linux

Code: Select all

#include <iostream>
using std::cout;  using std::endl;

// Reference : http://en.wikipedia.org/wiki/ANSI_escape_code#graphics

enum ANSI_Attrib { ANSI_Reset=0, ANSI_Bright=1, ANSI_Faint=2,
                   ANSI_Underline=4, ANSI_Blink_Slow=5,
                   ANSI_Blink_Rapid=6, ANSI_Inverse=7,
                   ANSI_Font_Std=10,
                   ANSI_Font1=11, ANSI_Font2=12, ANSI_Font3=13,
                   ANSI_Font4=14, ANSI_Font5=15, ANSI_Font6=16,
                   ANSI_Font7=17, ANSI_Font8=18, ANSI_Font9=19,
                   ANSI_Normal=22, ANSI_NonItalic=23, ANSI_Underline_Off=24,
                   ANSI_Black=30, ANSI_Red=31, ANSI_Green=32, ANSI_Yellow=33,
                   ANSI_Blue=34,  ANSI_Magenta=35, ANSI_Cyan=46, ANSI_White=37,
                   ANSI_StdColor = 39,
                   ANSI_B_Black=40, ANSI_B_Red=41, ANSI_B_Green=42, ANSI_B_Yellow=43,
                   ANSI_B_Blue=44,  ANSI_B_Magenta=45, ANSI_B_Cyan=46, ANSI_B_White=47,
                   ANSI_B_StdColor=49 };
int main() {
  char CSI[] = "\x1b[\0", CSI_End='m', CSI_Sep=';';
  cout << CSI << ANSI_Blink_Slow << CSI_End 
       << CSI << ANSI_Bright << CSI_Sep << ANSI_Red << CSI_End << "Hello"
       <<endl;
  return 0;
}
Unfortunately, this doesn't work (i.e. no color) when run under Windows/MinGW.
Is it possible to get this running under MinGW?

Many thanks for a hint,
Helmut.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: ANSI Control Code on Windows Console Project

Post by eranif »

The Windows CMD does not support the coloring escape sequences that are used on Linux boxs.

http://msdn.microsoft.com/en-us/library/ms686974.aspx
Eran
Make sure you have read the HOW TO POST thread
HJarausch
CodeLite Veteran
Posts: 98
Joined: Thu Feb 18, 2010 10:54 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: ANSI Control Code on Windows Console Project

Post by HJarausch »

Many thanks, Eran.

Helmut.
Post Reply