This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Color Output with Printf


A few weeks ago I asked if it was possible to build a binary with cygwin
that does not required cygwin1.dll.

I got back three different answers:
    (1) "try searching the mailing list archives for -mno-cygwin"
    (2) "You can't"
    (3) "Read the FAQ entry"

Thanks to everyone who took the time to reply.

It turns out that (1) worked for me (you can in fact build such a binary,
under some contraints). Now I have a question about ANSI color. I have
searched the archives and looked through the FAQ and I didn't find anything
that answered this question. My apologies if it has already been discussed
to death in some obvious location that slipped my mind :-).

Consider the following program:

    int main() {
	printf("%c[1;31mHello\n",27); /* Prints "Hello\n" in RED (ANSI) */
	return 0;
    }

The problem is that it only works in some cases. Sometimes I see the escape
codes echoed to the screen instead of seeing red text.

Here are three compilation methods and two display environments (command
and cmd behave identically):

				RXVT		"cmd.exe" (dos prompt)
gcc hello.c			red		red
gcc hello.c -mno-cygwin		red		fails
cl hello.c			red		fails

Where "red" means that it works as expected (red text) and "fails" means
that it didn't work (I saw the escape codes instead of them turning the
text red). cl is the MS command-line C compiler, version 12.00.8804. RXVT
is the version 2.7.2 (the one that came with cygwin for me, IIRC).

Changing printf to fwrite or write has no effect. Putting flushes in there
has no effect.

Clearly it is possible to get red text in a dos prompt window: cygwin does
it somehow. My personal theory is that the normal cygwin version is doing
some special setup before main is called that causes stdout to be treated
differently.

I would like to get red text in a dos window without with either
gcc -mno-cygwin or cl. Does anyone know how to do this? Does anyone know
why "gcc" and "gcc -mno-cygwin" behave differently in this regard?

Does anyone know what sort of setup things the cygwin version might be
doing (so that I can manually copy them)?

Thanks!

	- Wes


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]