Strange console IO behavior (at least on Windows)

The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the fly, with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys. Under Windows, I have to press enter before anything is printed to the screen. It then always prints 71 (that's upper G, no idea where that comes from), and then blocks. Pressing enter again prints the codes of all characters typed, except the first one, following by the two codes of the linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER again, I get 98 99 10 10. Under msys, it just ignores both the hSetBuffering and hSetEcho, but when hitting enter, it at least prints the codes correctly. How does it behave under OSX and Linux? Is this a bug or am I doing something wrong?

On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen
The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the fly, with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys. Under Windows, I have to press enter before anything is printed to the screen. It then always prints 71 (that's upper G, no idea where that comes from), and then blocks. Pressing enter again prints the codes of all characters typed, except the first one, following by the two codes of the linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER again, I get 98 99 10 10. Under msys, it just ignores both the hSetBuffering and hSetEcho, but when hitting enter, it at least prints the codes correctly. How does it behave under OSX and Linux? Is this a bug or am I doing something wrong?
For me on OSX it has the intended behavior. Which is to say, every time I type a key I see the ascii value of the key. I have no idea why windows is being different. Jason

Okay, I'll file a bug report. Maybe someone else on Windows could confirm
this behavior?
On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit
On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen
wrote: The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the fly, with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys. Under Windows, I have to press enter before anything is printed to the screen. It then always prints 71 (that's upper G, no idea where that comes from), and then blocks. Pressing enter again prints the codes of all characters typed, except the first one, following by the two codes of the linefeeds. So e.g. when I type "abc" ENTER, I get 71, then hitting ENTER again, I get 98 99 10 10. Under msys, it just ignores both the hSetBuffering and hSetEcho, but when hitting enter, it at least prints the codes correctly. How does it behave under OSX and Linux? Is this a bug or am I doing something wrong?
For me on OSX it has the intended behavior. Which is to say, every time I type a key I see the ascii value of the key. I have no idea why windows is being different.
Jason

On Sat, Aug 22, 2009 at 2:37 PM, Peter Verswyvelen
Okay, I'll file a bug report. Maybe someone else on Windows could confirm this behavior? On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit
wrote: On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen
wrote: The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the fly, with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys.
This is probably the following issue: http://hackage.haskell.org/trac/ghc/ticket/2189 -Judah

Yep, that seems to be it. I should first do a search on trac before spamming
here!
But my first reaction when something basic as this goes wrong is blame
myself and ask for help :-)
On Sat, Aug 22, 2009 at 11:40 PM, Judah Jacobson
On Sat, Aug 22, 2009 at 2:37 PM, Peter Verswyvelen
wrote: Okay, I'll file a bug report. Maybe someone else on Windows could confirm this behavior? On Sat, Aug 22, 2009 at 11:36 PM, Jason Dagit
wrote: On Sat, Aug 22, 2009 at 2:14 PM, Peter Verswyvelen
wrote: The following program http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8445#a8445 should echo the ASCII code of each character the user types, on the
fly,
with no line buffering whatsoever. But it doesn't. At least not under Windows's cmd, and even less with msys.
This is probably the following issue:
http://hackage.haskell.org/trac/ghc/ticket/2189
-Judah

Yeah, it's broken in windows. Here's the workaround courtesy of Alistar Bayley. (ticket 2189) {-# LANGUAGE ForeignFunctionInterface #-} import Data.Char import Control.Monad (liftM, forever) import Foreign.C.Types getHiddenChar = liftM (chr.fromEnum) c_getch foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt main = do forever $ do c <- getHiddenChar putStrLn $ show (fromEnum c)
participants (4)
-
Jason Dagit
-
Judah Jacobson
-
Peter Verswyvelen
-
Tim Attwood