petscii-bbs icon indicating copy to clipboard operation
petscii-bbs copied to clipboard

When to use flush() and resetInput()

Open ssshake opened this issue 5 years ago • 4 comments

I've been trying to understand when these need to be used and what they do but I don't follow it.

Could you give me some guidance on when to use either of these and why. Thanks!

ssshake avatar Oct 30 '19 14:10 ssshake

Hi,

flush() function writes to output channel all characters that could have been buffered until that moment.

resetInput() acts as "reset keyboard buffer" (so it's related to input channel), it's useful before getting an input from keyboard, with readKey or readLine()

Hope it helps!

sblendorio avatar Oct 30 '19 14:10 sblendorio

It does help.

What are the potential consequences of not using either?

I've realized in my code I am using (or rather not using) these haphazardly and without any thought or understanding.

Everything seems to be behaving fine but I'm guessing there is some nuance there depending on my connection quality and terminal client.

ssshake avatar Oct 30 '19 14:10 ssshake

It depends on the client used. For example, if I don't user flush(), sometimes using SyncTerm some characters are "retained" till some other char comes.

sblendorio avatar Oct 30 '19 14:10 sblendorio

OK got it, thanks!

ssshake avatar Oct 30 '19 14:10 ssshake