
Hello, I have a similar question. When I use getChar with Hugs the newline (caused by pressing 'Enter') seems to be carried over into the next call of main, where it is treated as a single input character. The workaround is getLine and head, but it would be nice to drop the newline right away. I suppose the solution offered here: hSetBuffering stdin NoBuffering will have the desired effect, but is there another way? Thanks, Hans van Thiel

Hi
I have a similar question. When I use getChar with Hugs the newline (caused by pressing 'Enter') seems to be carried over into the next call of main, where it is treated as a single input character. The workaround is getLine and head, but it would be nice to drop the newline right away. I suppose the solution offered here:
Hmm, sounds like a bug in WinHugs, I'll check it out. Thanks Neil

No, it happens with Hugs on Fedora Core 5 (the fc5 Hugs package), not WinHugs. Thanks, Hans On Tue, 2006-10-24 at 17:27 +0100, Neil Mitchell wrote:
Hi
I have a similar question. When I use getChar with Hugs the newline (caused by pressing 'Enter') seems to be carried over into the next call of main, where it is treated as a single input character. The workaround is getLine and head, but it would be nice to drop the newline right away. I suppose the solution offered here:
Hmm, sounds like a bug in WinHugs, I'll check it out Thanks
Neil

No, it happens with Hugs on Fedora Core 5 (the fc5 Hugs package), not WinHugs.
Woops, the previous post in a different thread was talking about WinHugs, and I forgot to context-switch :) Does GHCi give the different behaviour? If so, one of them is probably a bug. Thanks Neil
Thanks,
Hans
On Tue, 2006-10-24 at 17:27 +0100, Neil Mitchell wrote:
Hi
I have a similar question. When I use getChar with Hugs the newline (caused by pressing 'Enter') seems to be carried over into the next call of main, where it is treated as a single input character. The workaround is getLine and head, but it would be nice to drop the newline right away. I suppose the solution offered here:
Hmm, sounds like a bug in WinHugs, I'll check it out Thanks
Neil

On Tue, Oct 24, 2006 at 06:14:14PM +0200, Hans van Thiel wrote:
I have a similar question. When I use getChar with Hugs the newline (caused by pressing 'Enter') seems to be carried over into the next call of main, where it is treated as a single input character. The workaround is getLine and head, but it would be nice to drop the newline right away. I suppose the solution offered here:
that is the correct behavior, input is never discarded, it is just saved up until you press enter for the first time. if you type foo<enter>, your next four getChars will get 'f' 'o' 'o' and '\n'. it is not haskell that is treating enter as specially, it is your terminal, getChar just returns exactly what was passed to it.
hSetBuffering stdin NoBuffering
will have the desired effect, but is there another way?
this will cause getChar to return right away as soon as they type the first character. which is probably what you want. of course, if they press an enter, you will see an enter. but you don't have to wait until they press one. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (3)
-
Hans van Thiel
-
John Meacham
-
Neil Mitchell