|
From: Joshua N. <nek...@qw...> - 2002-07-25 02:57:18
|
I'm trying to write a terminal/console mode program that uses colors. A =
simple example:
#include <stdio.h>
int main(void)
{
printf("\033[32mHello World\033[39m\n");
return 0;
}
This works perfectly on unix systems as the way most color xterms =
support colors is by using ansi escape sequences. This also works with =
rxvt that comes with the msys environment. Thing is, it will not work in =
a normal dos box. The escape character \033 gets printed as an graphics =
character and the [33m appears as regular text.=20
Now the 'ls --color' works properly in a dos box, so I know it is =
possiable to do this in a regular dos box. As a matter of fact, if I run =
the following in a dos box, the output of my program appears in color =
just fine.
test | cat
I've even tried redirecting the output from the cat to a file to see =
exactly what's is being output
test | cat > catoutput.txt
test > testoutput.txt
Both are identical ??? If I cat either one, they both appear in color. =
If I issue 'type output.txt', the escape sequence appears as normal text =
and I get no color. I've done the same with the output from 'ls --color' =
with the same results.
Now I've tried looking at the source for ls.c and couldn't see anything =
special. They just did a simple putchar(ESC SEQUENCE). Compiled the =
textutils cat that comes with msys-1.0.7. When I ran it on my previous =
output files, the output was no longer in color ??? I am using =
msys-1.0.8 though. Couldn't find the src download for it, and when I =
grabbed the latest CVS sources, textutils wasn't in there???
If anyone has a clue what's going on, I'd appreciate a hint. I'm =
>guessing< that some of these utilities may have been linked with a =
different C runtime library, one that passes stdout through some kind of =
filter which remaps the ESC sequences to whatever M$ wants if the output =
isatty()/console.
Josh
|