Synchronous Non-blocking read from stdin

Hi there, I fail to figure out how should I implement this:

I have a CLI which blocks user input after each question, what I try to implement is to consume any pending input before I write the next question, so that earlier typing (if any) is discarded. I am one of those who press enter twice, or more times and every time I do I have to start the program all over.

So far I found blocking reads from stdin like read_line or a complete async infrastructure, which for this use case I would prefer to avoid.
I found as well has_data_left, BufRead in std::io - Rust which up front looks like what I need, but unfortunately, it is experimental.

Does anyone of you know about a stable workaround that I could use? It could be possible that there is even an easier way to implement a solution, any ideas?

thanks in advance.

1 Like

Is this SO answer helpful to you?

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.