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

Don't return when not reading any input events #2

Merged
merged 3 commits into from
Oct 8, 2019
Merged

Conversation

TimonPost
Copy link
Member

Attempt to fix crossterm-rs/crossterm#195

So this is an 'attempt' to fix this issue, altough I am not sure we should do something like this. I have checked the .Net framework source code out and they seem to do this the same way. This could be a temporary fix until we are going to refactor the input crate.

Copy link

@matprec matprec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the .Net implementation does something slightly different, they loop on events they choose not to handle while the proposed implementation busy-loops over unavaible input.

I've left some comments, i think we can replicate their behaviour quiet closely:

src/console.rs Outdated Show resolved Hide resolved
src/console.rs Outdated Show resolved Hide resolved
src/console.rs Outdated Show resolved Hide resolved
@TimonPost
Copy link
Member Author

TimonPost commented Oct 5, 2019

Ahhh, so if we remove that 0 check, it will start a read operation, but because there is no input, it will block read right? And thus no need for any kind of loop.

@matprec
Copy link

matprec commented Oct 6, 2019

Ahhh, so if we remove that 0 check, it will start a read operation, but because there is no input, it will block read right?

Exactly!

And thus no need for any kind of loop.

I beg to differ - this way, the iterator will still yield None values for unknown events even though known event might occure later, which will short circuit patterns like this:

for _ in input.read_sync() {
    println!("Hello World!");
}

Looping internally in read_single_event until an known event occurs would enable such patterns.

@TimonPost TimonPost merged commit eea5cea into master Oct 8, 2019
@TimonPost TimonPost mentioned this pull request Oct 19, 2019
7 tasks
@zrzka zrzka deleted the read_sync branch October 19, 2019 13:29
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

Successfully merging this pull request may close these issues.

Make read sync block for windows systems
2 participants