sblendorio / petscii-bbs

A Java framework for building highly customizable PETSCII-enabled BBS, accessible from Commodore 64/128
Mozilla Public License 2.0
121 stars 16 forks source link

When to use flush() and resetInput() #27

Open ssshake opened 5 years ago

ssshake commented 5 years ago

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!

sblendorio commented 5 years ago

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!

ssshake commented 5 years ago

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.

sblendorio commented 5 years ago

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.

ssshake commented 5 years ago

OK got it, thanks!