
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. Yes, but the problem is with two subsequent runs of main. I'd have thought the buffer would flush automatically and the second run would start with an empty buffer. Now I enter 'b', then press 'Enter' and it works as expected. Then I 'main' again, and it terminates right away with a blank line. If I enter 'a', 'b' and then Enter, the second run takes the second character. If I'm not doing anything wrong (always a possibility :-), then it seems more like a (small) bug in Hugs, as Neil suggested. I'll have to check what chgi does. John -- John Meacham - ⑆repetae.net⑆john⑈ Regards, Hans

On Wed, Oct 25, 2006 at 06:57:38PM +0200, Hans van Thiel wrote:
Yes, but the problem is with two subsequent runs of main. I'd have thought the buffer would flush automatically and the second run would start with an empty buffer. Now I enter 'b', then press 'Enter' and it works as expected. Then I 'main' again, and it terminates right away with a blank line.
That is normal Unix behaviour. Try the same input with head -1c | od -c; head -1c | od -c The terminal buffer is only discarded if a program changes the terminal mode. Hugs and ghci do (because they use readline), but runhugs doesn't.
participants (2)
-
Hans van Thiel
-
Ross Paterson