"hSetBuffering stdin NoBuffering" messes up terminal

Ferenc Wagner wferi at afavant.elte.hu
Fri Oct 17 19:46:29 EDT 2003


Glynn Clements <glynn.clements at virgin.net> writes:

> David Roundy wrote:
>
>> On my terminal (aterm), calling
>>
>> hSetBuffering stdin NoBuffering
>>
>> within my program messes up the terminal settings somehow
>> [...]
>
> 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 mode).

According to me, hSetBuffering should not touch the terminal
settings ever.  It is not mentioned in the Report and it is
not implied by its name.  It only leads to confusion.

> 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.

In my experience, one seldom wants to do this.  There are
specialised libraries which do things like this well and
easily.  Each time I wanted unbuffered input terminal was
used for testing only, in which case backspace is useful.

For stupid little programs we could provide some stupid
little functions which have the word 'Magic' in their
name, instead of abusing standard operations.

Strictly in my opinion,
Feri.


More information about the Haskell-Cafe mailing list