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]

RE: Color Output with Printf


I'm not certain how cygwin/UNIX handles color, but I do know that in the DOS
of old, you relied on a TSR (ANSI.SYS) to handle the escape codes which gave
you color. I would also guess that these escape codes are not the same as
the UNIX color escape codes (too long ago to remember them).

Sure enough, type "echo [1;31mHello" into DOS prompt, and you get
"[1;31mHello"

My guess is the cygwin dll kindly takes care of your color output from
printf (else it gets lost). To get color in a standard DOS box, you'll have
to locate how you would do it normally from DOS.

If you can find escape codes that work from the command line using echo,
these will probably also work from printf (but not in cygwin?).

Dave.

PS. Did a quick search: the escape syntax that _was_ used by ANSI.SYS is
summarised here
http://www.delmar.edu/Courses/CIS415L/ANSIsys.htm
No guarantees that this is valid for more recent versions of
command.com/cmd.exe with or without ANSI.SYS.

> -----Original Message-----
> From: Westley Weimer [mailto:weimer@EECS.Berkeley.EDU]
> Sent: Thursday, May 02, 2002 5:41 PM
> To: cygwin@cygwin.com
> Cc: weimer@cs.berkeley.edu
> Subject: 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/
> 
> 


--
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]