
Hi, How can I read a single character from standard output? I would like the user to press a single key and the reading function return imediately after that key is pressed. Thanks, Maurício

briqueabraque:
Hi,
How can I read a single character from standard output? I would like the user to press a single key and the reading function return imediately after that key is pressed.
so you want a function of type: IO Char asking Hoogle (http://haskell.org/hoogle) we get: Prelude. getChar :: IO Char IO. hGetChar :: Handle -> IO Char -- Don

Donald Bruce Stewart wrote:
briqueabraque:
Hi,
How can I read a single character from standard output? I would like the user to press a single key and the reading function return imediately after that key is pressed.
so you want a function of type: IO Char
asking Hoogle (http://haskell.org/hoogle) we get: Prelude. getChar :: IO Char IO. hGetChar :: Handle -> IO Char
-- Don
getChar doesn't return until I press Enter. I need something that returns immediately after I press any key. Thanks, Maurício

Hi
getChar doesn't return until I press Enter. I need something that returns immediately after I press any key.
It's a problem with buffering: http://haskell.org/hoogle/?q=buffering suggests: hSetBuffering stdin NoBuffering Thanks Neil

On 10/23/06, Neil Mitchell
Hi
getChar doesn't return until I press Enter. I need something that returns immediately after I press any key.
It's a problem with buffering:
hSetBuffering stdin NoBuffering
This usually doesn't work on Windows: GHC 6.4.2 and 6.6: requires <enter> Hugs (console) Sept. 2006: requires <enter> WinHugs (GUI) Sept. 2006: works as expected But it seems to work on Linux: GHC 6.4.1 on Ubuntu 6.06: works as expected GHC 6.6 on Ubuntu 6.06: works as expected I am really interested in hearing of a solution that works on all platforms.
import IO main = do hSetBuffering stdin NoBuffering hGetChar stdin
Regards, Brian

Hi
> getChar doesn't return until I press Enter. I need something that > returns immediately after I press any key.
It's a problem with buffering:
hSetBuffering stdin NoBuffering
This usually doesn't work on Windows:
GHC 6.4.2 and 6.6: requires <enter> Hugs (console) Sept. 2006: requires <enter> WinHugs (GUI) Sept. 2006: works as expected
But it seems to work on Linux: GHC 6.4.1 on Ubuntu 6.06: works as expected GHC 6.6 on Ubuntu 6.06: works as expected
I am really interested in hearing of a solution that works on all platforms.
Does 'readKey', from System.Console.Readline, works on Windows? It works on Linux with the buffering advice applied. Maurício

Hi! Sorry if it is a bit off-topic in this thread. How can I input EOF symbol in WinHugs? Ctrl-Z and Ctrl-D don't work for me, so I can't use getContents function. Maybe there is a piece of documentation that I should read? Thanks! -- Dimitri

H
How can I input EOF symbol in WinHugs?
No possible way. If you could type the NUL character that might possibly work, but even then 1) you can't, 2) it might not. Do you have a particular need for typing the "end of getContents" in WinHugs? If so, I can open a bug and might be able to fix it for the next release. Thanks Neil

On 10/25/06, Neil Mitchell
How can I input EOF symbol in WinHugs?
No possible way. If you could type the NUL character that might possibly work, but even then 1) you can't, 2) it might not.
Do you have a particular need for typing the "end of getContents" in WinHugs? If so, I can open a bug and might be able to fix it for the next release.
Thank you! Surely I can get along without getContents in WinHugs: last time I thought about it I just wanted to show getContents function to my students (and using hGetContents on a file handle seems to be better example). Another function that could be useful when teaching IO is 'interact', and it seems that it's also impossible to use it without typing EOF (am I right?). So it would be nice to have a way to type EOF in WinHugs, but surely it's a feature one can live without. And thank you for WinHugs, it is really useful! -- Dimitri

Hi
Surely I can get along without getContents in WinHugs: last time I thought about it I just wanted to show getContents function to my students (and using hGetContents on a file handle seems to be better example). Another function that could be useful when teaching IO is 'interact', and it seems that it's also impossible to use it without typing EOF (am I right?).
You can use interact, you just have to hit the stop button to break out of it. Interestingly Ctrl+C is captured by interact, as is Ctrl+Z/Ctrl+D, so fixing it up to return -1 in these cases should be pretty easy - i'll try and get that done tomorrow.
And thank you for WinHugs, it is really useful!
Thank you :) - its nice to know that it is being used. Neil

Hi
Do you have a particular need for typing the "end of getContents" in WinHugs? If so, I can open a bug and might be able to fix it for the next release.
Thank you!
Fixed in the CVS version, the next release will allow Ctrl+Z or Ctrl+D to terminate an input stream. There were also a few additional fixes around the interact code that I made. If you want to use these fixes before the next release: http://haskell.org/hoogle/other/winhugs-interact-fixes-2006-oct-25.zip Extract winhugs.exe and replace the existing winhugs.exe in a Sep 2006 installation. Thanks Neil

Hi!
It works very well, thank you!
On 10/25/06, Neil Mitchell
Fixed in the CVS version, the next release will allow Ctrl+Z or Ctrl+D to terminate an input stream. There were also a few additional fixes around the interact code that I made.
If you want to use these fixes before the next release:
http://haskell.org/hoogle/other/winhugs-interact-fixes-2006-oct-25.zip
Extract winhugs.exe and replace the existing winhugs.exe in a Sep 2006 installation.
-- Dimitri

On Wed, Oct 25, 2006 at 01:06:28AM +0400, Dimitri Timofeev wrote:
Sorry if it is a bit off-topic in this thread. How can I input EOF symbol in WinHugs? Ctrl-Z and Ctrl-D don't work for me, so I can't use getContents function. Maybe there is a piece of documentation that I should read?
does F6 work? it used to back with DOS something or another. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (6)
-
Brian Smith
-
Dimitri Timofeev
-
dons@cse.unsw.edu.au
-
John Meacham
-
Maurício
-
Neil Mitchell