Subject: Re: Color Output with Printf
From: Sam Edge <[email-masked]>
To: [email-masked]
Date: Thu, 02 May 2002 23:12:04 +0100

Westley Weimer wrote in
<[email-masked]>
on Thu, 2 May 2002 14:41:24 -0700 (PDT):

> 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 assume that a Cygwin application running directly in a console
window has its standard I/O passed through a terminal emulator inside
cygwin1.dll, yes. This appears to be using the WriteConsoleOutput
Win32 API call to write both text and attribute information to the
console window.

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

As described above, there must be a basic terminal emulator in
cygwin1.dll that provides the cygwin terminal type. If you don't link
with this then your code will end up writing directly to the console
window without setting attributes. (The console itself doesn't
understand ANSI sequences.)

For a non-Cygwin application you need to use the Win32 console output
routines. Take a look at WriteConsoleOutput and
WriteConsoleOutputAttribute in the Win32 API for setting colours.

If you don't have MSDN on CD, you should check out the on-line
version, in this case
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/conchar_9ktw.asp

-- 
Sam Edge

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