"hSetBuffering stdin NoBuffering" messes up terminal
glynn.clements at virgin.net
Tue Oct 14 15:43:07 EDT 2003
David Roundy wrote:
> On my terminal (aterm), calling
> hSetBuffering stdin NoBuffering
> within my program messes up the terminal settings somehow, so that
> backspace no longer works when I run my program (without the NoBuffering) a
> second time. The 'reset' command fixes the problem, so once again
> backspace works, but my program shouldn't be affecting the terminal state
> at all. A simple call to hSetBuffering stdin LineBuffering doesn't seem to
> fix the problem. Any ideas what might be going on here? It's really
> annoying to not be able to use backspace when entering data.
Disabling buffering with hSetBuffering not only disables the
user-space buffering (analogous to setvbuf() etc in C), it also
disables the terminal's buffering (more precisely, disables canonical
However, re-enabling buffering (setting the mode to something other
than NoBuffering) should re-enable canonical mode in the terminal. Of
course, this doesn't help if your program terminates before buffering
You can use the functions in the PosixTTY module to explicitly
control the terminal state.
BTW, if your program actually needs unbuffered terminal input (i.e.
you want to receive individual key codes without waiting for the user
to hit Return), and hSetBuffering didn't change the terminal settings,
you would have to do it yourself anyhow, leading to the same issues.
Glynn Clements <glynn.clements at virgin.net>
More information about the Haskell-Cafe