[Haskell-cafe] Windows console

Jonathan Cast jonathanccast at fastmail.fm
Tue Sep 9 15:20:50 EDT 2008


On Tue, 2008-09-09 at 20:15 +0100, Andrew Coppin wrote:
> When coding in a POSIX-compliant environment, you can usually write 
> special escape codes to the console to change the text colour and so 
> forth. However, this does not work on Windows.
> 
> (Ignore all references you see to enabling ANSI.SYS in your config.sys 
> file; this applies only to 16-bit MS-DOS programs, *not* to 32-bit 
> Windows programs.)
> 
> However - to my surprise - apparently the Win32 API provides a set of 
> function calls that do in fact allow 32-bit applications to change the 
> colours of the console on a character-by-character basis. However - wait 
> for it - those *particular* functions aren't in Haskell's 
> System.Win32.Console module. :-(
> 
> Obviously, I know nothing about C. However, after much hunting around, 
> it turns out that for some reason, GHC appears to ship with a complete 
> set of C header files for the Win32 API. (In other words, the necessary 
> header file for accessing the functions I want is there.) After 
> staggering through the (very unhelpful) FFI language specification, I 
> was able to make it so that I can apparently call these functions from 
> Haskell. I was not, however, able to find any way at all to import the 
> symbolic constants necessary, so I was forced to reading through the 
> source code of the raw C header files to find out what the numeric 
> values of these are (!!!)

c2hs can do this; check out #const CONSTANT_NAME

jcc




More information about the Haskell-Cafe mailing list