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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ impl Console {
}

pub fn read_single_input_event(&self) -> Result<Option<InputRecord>> {
TimonPost marked this conversation as resolved.
Show resolved Hide resolved
let buf_len = self.number_of_console_input_events()?;

// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
return Ok(None);
}
// loop until we have events, TODO: replace with async
loop {
TimonPost marked this conversation as resolved.
Show resolved Hide resolved
let buf_len = self.number_of_console_input_events()?;

let mut buf: Vec<INPUT_RECORD> = Vec::with_capacity(1);
let mut size = 0;
// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
TimonPost marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

let a = self.read_input(&mut buf, 1, &mut size)?.1[0].to_owned();
let mut buf: Vec<INPUT_RECORD> = Vec::with_capacity(1);
let mut size = 0;

// read single input event
Ok(Some(a))
return Ok(Some(self.read_input(&mut buf, 1, &mut size)?.1[0].to_owned()));
}
}

pub fn read_console_input(&self) -> Result<(u32, Vec<InputRecord>)> {
Expand Down