console-rs/console

How to flush stdin buffer before calling `read_key()`?

icorbrey opened this issue · 0 comments

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?