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

How to flush stdin buffer before calling read_key()? #187

Open
icorbrey opened this issue Sep 30, 2023 · 0 comments
Open

How to flush stdin buffer before calling read_key()? #187

icorbrey opened this issue Sep 30, 2023 · 0 comments

Comments

@icorbrey
Copy link

I'd like to be able to prevent keypresses from being recognized before read_key() is actually called. Currently I'm doing the following:

let term = Term::stdout();

thread::sleep(Duration::from_secs(5));

match term.read_key()? {
    _ => ...
}

I'd like for any keypresses that occur while the thread is asleep to not be registered, but if I press something during the timeout it still registers once the timeout is complete. I've tried calling flush(), but this seems to only affect stdout, not stdin:

let term = Term::stdout();

thread::sleep(Duration::from_secs(5));
term.flush()?;

match term.read_key()? {
    _ => ...
}

Thoughts?

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

1 participant