Eager IO function
Simon Marlow
simonmar@microsoft.com
Wed, 13 Feb 2002 13:23:44 -0000
> > How should I modify the function below so that characters=20
> are printed
> > out as they arrive?
> >=20
> > printchar :: Handle -> IO ()
> > printchar handle =3D do c <- hGetChar handle
> > putChar c
>=20
> Try using
> hSetBuffering handle NoBuffering
> hSetBuffering stdout NoBuffering
> from the IO library, before you call printchar. If the input handle
> is attached to a terminal, you may also need to adjust the terminal
> emulation into `cbreak' mode, e.g. with
> System.system "stty cbreak"
> Don't forget to reset the terminal afterwards!
GHC does the "stty cbreak" step for you, if the handle on which you set =
the buffering mode is a terminal. Note also that not all systems have =
an 'stty' command.
Cheers,
Simon