POV-Ray : Newsgroups : povray.off-topic : Colour consoles Server Time
7 Sep 2024 11:23:34 EDT (-0400)
  Colour consoles (Message 1 to 10 of 33)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Colour consoles
Date: 20 Aug 2008 09:08:38
Message: <48ac1756$1@news.povray.org>
You *know* something's wrong when you find yourself envying people who 
use Unix because it can emulate an obsolete VT100... o_O

Basically, I have a perfectly working console application, but I wish I 
could just make certain parts of its output come out in a different 
colour. On Unix, this would be a fairly trivial matter of writing some 
escape codes to stdout and you're done. On Windoze... well that doesn't 
work.

I wonder... Is there some function call in the Win32 API that can 
actually change the colour of the text in a console window? Or is that 
impossible? Does anybody here know the Win32 API well enough to know the 
answer?

(Certainly the "color" command changes the colours of the console window 
- but it changes the colour of *everything*. I don't know if you can 
change just some of the text, rather than all of it...)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: Colour consoles
Date: 20 Aug 2008 10:03:09
Message: <op.uf6uniy17bxctx@e6600>
On Wed, 20 Aug 2008 15:08:37 +0200, Invisible <voi### [at] devnull> wrote:
> Basically, I have a perfectly working console application, but I wish I  
> could just make certain parts of its output come out in a different  
> colour. On Unix, this would be a fairly trivial matter of writing some  
> escape codes to stdout and you're done. On Windoze... well that doesn't  
> work.

NT-based console windows do not support colour escape codes. Only 16-bit  
applications (running under NTVDM) can use colour escapes.


> I wonder... Is there some function call in the Win32 API that can  
> actually change the colour of the text in a console window?

http://msdn.microsoft.com/en-us/library/ms682088.aspx



-- 
FE


Post a reply to this message

From: Invisible
Subject: Re: Colour consoles
Date: 20 Aug 2008 10:12:10
Message: <48ac263a$1@news.povray.org>
>> On Unix, this would be a fairly trivial matter of writing some 
>> escape codes to stdout and you're done. On Windoze... well that 
>> doesn't work.
> 
> NT-based console windows do not support colour escape codes. Only 16-bit 
> applications (running under NTVDM) can use colour escapes.

Indeed. So that isn't much help.

>> I wonder... Is there some function call in the Win32 API that can 
>> actually change the colour of the text in a console window?
> 
> http://msdn.microsoft.com/en-us/library/ms682088.aspx

Bugger. I don't have bindings for those particular functions. :-(

I wonder if I could write some...?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Invisible
Subject: Re: Colour consoles
Date: 20 Aug 2008 10:54:03
Message: <48ac300b$1@news.povray.org>
Fredrik Eriksson wrote:

> http://msdn.microsoft.com/en-us/library/ms682088.aspx

Oh. My. God.

I literally can't believe this... I just wrote and compiled a C program 
that calls the Win32 API directly, AND IT FRIGGIN WORKED!! 0_0

*dies*

I would never have believed it was possible... I was sure it would 
blue-screen the machine or crash spectacularly, but no, it actually 
worked properly. (AND, best of all, it IS possible to change the colour 
of just some characters in a console window. I wasn't sure it could be 
done.)

I was a little shocked to discover that I already have the necessary C 
header files. And, obviously, it took a litle while to figure out how to 
make my Haskell compiler compile raw C files instead of Haskell programs.

The hardest part was figuring out what "warning: function foo() defined 
implicitly" means. Apparently it means you spelt the function's name 
wrong, so the compiler couldn't find it in the header file. This also 
causes the linker to make rude comments.

But once you get over all of these things... my God, I made a direct OS 
call and *didn't* crash the OS. Astonishing!

I think I need to go sit down...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Doctor John
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:01:39
Message: <48ac31d3$1@news.povray.org>
Invisible wrote:
> Oh. My. God.
> 
> I literally can't believe this... I just wrote and compiled a C program 
> that calls the Win32 API directly, AND IT FRIGGIN WORKED!! 0_0
> 
> *dies*

..and it only took you twelve minutes!
*Falls_over_in_amazement*

John
-- 
"Eppur si muove" - Galileo Galilei


Post a reply to this message

From: Invisible
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:20:18
Message: <48ac3632@news.povray.org>
Doctor John wrote:

> ..and it only took you twelve minutes!
> *Falls_over_in_amazement*

Really? Gee, it seemed like much longer than that to me...

The hard part, of course, is writing some Haskell bindings. ;-) In 
particular, I cannot for the life of me figure out how to get at 
symbolic constant names. :-(

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Jim Henderson
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:38:38
Message: <48ac3a7e$1@news.povray.org>
On Wed, 20 Aug 2008 16:20:17 +0100, Invisible wrote:

> In
> particular, I cannot for the life of me figure out how to get at
> symbolic constant names. :-(

In C?  Look at #define

Jim


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:40:26
Message: <op.uf6y5oqx7bxctx@e6600>
On Wed, 20 Aug 2008 17:20:17 +0200, Invisible <voi### [at] devnull> wrote:
> The hard part, of course, is writing some Haskell bindings. ;-) In  
> particular, I cannot for the life of me figure out how to get at  
> symbolic constant names. :-(

If you are looking for 'FOREGROUND_BLUE' and the like, they are defined in  
'WinCon.h'. There you will also find the structure definitions relevant to  
the console subsystem.



-- 
FE


Post a reply to this message

From: Invisible
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:42:13
Message: <48ac3b55$1@news.povray.org>
>> In
>> particular, I cannot for the life of me figure out how to get at
>> symbolic constant names. :-(
> 
> In C?  Look at #define

I meant how to get that stuff into Haskell.

It seems Haskell provides a magical command which somehow lets you call 
a C function as if it's a Haskell function, assuming you can find a 
header file that contains the C function you're after. (I literally have 
*no idea* how the linker finds the actual code...) However, there seems 
to be no way to import constants. In fact, every Haskell binding I've 
looked at has these hard-coded in the Haskell source code rather than 
imported, so I've just waded through a few KB of header files tracking 
down all the #defines and their literal values.

And you know what?

I just ported my program to Haskell, AND IT STILL WORKS CORRECTLY! 0_0

This is an unprecidented level of success. It seems I can actually call 
any C function I have a header file for. Wow.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Darren New
Subject: Re: Colour consoles
Date: 20 Aug 2008 11:43:05
Message: <48ac3b89$1@news.povray.org>
Fredrik Eriksson wrote:
> NT-based console windows do not support colour escape codes. Only 16-bit 
> applications (running under NTVDM) can use colour escapes.

So this doesn't work?

http://www.windowsnetworking.com/kbase/WindowsTips/Windows2000/UserTips/Miscellaneous/CommandInterpreterAnsiSupport.html


-- 
Darren New / San Diego, CA, USA (PST)


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.