[Haskell-cafe] Character I/O
ekmett at gmail.com
Tue Mar 31 15:44:18 EDT 2009
You want to use:
> main = do hSetBuffering stdin NoBuffering; c <- getChar
Your problem is that by default, POSIX environments use line buffering on
stdin queuing up until it sees a carriage return before sending it to the
process. Which is in this case, your code.
On Tue, Mar 31, 2009 at 3:38 PM, Andrew Coppin
<andrewcoppin at btinternet.com>wrote:
> I ran the following program:
> >module Main where
> >main = do
> > putStrLn "Key"
> > c <- getChar
> > print c
> > main
> Unfortunately, it doesn't do what I was hoping. Specifically, it only
> returns any data when I hit [return]. It also seems to be giving me a
> command history somehow. Special keys (e.g., arrow keys, backspace, escape)
> don't get through to the application.
> I'm trying to write a program that uses individual keys as commands. What's
> the correct way to get this to work?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe