Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ssshake opened this issue Oct 30, 2019 · 4 comments
Open

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

ssshake opened this issue Oct 30, 2019 · 4 comments

Comments

@ssshake
Copy link

ssshake commented Oct 30, 2019

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
Copy link
Owner

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
Copy link
Author

ssshake commented Oct 30, 2019

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
Copy link
Owner

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
Copy link
Author

ssshake commented Oct 30, 2019

OK got it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants