pub fn create_event_receiver<R: Read + Send + 'static>(mut input: R) -> Receiver<io::Result<Event>> {
    let (tx, rx) = crossbeam_channel::unbounded();
    thread::spawn(move || {
        let mut offset = 0;
        // mouse event with both coords >100 takes 13 bytes, max found yet
        let mut buf = [0; 16];
        loop {
            let res = match input.read(&mut buf[offset..]) {
                Ok(bytes_read) => {
                    match bytes_read {
                        0 => break, // 0 bytes read means EOF
                        _ => {
                            let size = bytes_read + offset;
                            let (event, read) = parse_input_sequence(&buf[0..size]);
                            if read < size {
                                // store the unconsumed part as part of the next buffer
                                offset = size - read;
                                buf.copy_within(read..size, 0);
                            } else {
                                offset = 0;
                            }
                            tx.send(Ok(event))
                        }
                    }
                }
                Err(e) if e.kind() == ErrorKind::UnexpectedEof => break,
                Err(e) => tx.send(Err(e)),
            };
            if res.is_err() {
                // SendError only occurs when you close the channel, so we just shut down
                break;
            }
        }
    });
    rx
}
/// Creates a new instance of the receiver of the console events
/// that might be read from the given input.
///
/// It spins up a thread that will read the input forever, with no
/// means of stopping it other than closing the input or the receiver.
/// How the input closes depends on its implementation, but you can
/// simply drop the receiver.
/// Note that the thread would only close after it goes out of being
/// blocked by receiving some data from the input.
///
/// The algorithm relies on the fact that it reads individual key presses
/// as separate chunks, and when it receives a lot of bytes at once
/// it tries to parse sequences of them, checking how many bytes they consumed and
/// storing the excesses (when receiving events rapidly enough) for the next iterations
///
Creates a new instance of the receiver of the console events
that might be read from the given input.

It spins up a thread that will read the input forever, with no
means of stopping it other than closing the input or the receiver.
How the input closes depends on its implementation, but you can
simply drop the receiver.
Note that the thread would only close after it goes out of being
blocked by receiving some data from the input.

The algorithm relies on the fact that it reads individual key presses
as separate chunks, and when it receives a lot of bytes at once
it tries to parse sequences of them, checking how many bytes they consumed and
storing the excesses (when receiving events rapidly enough) for the next iterations
Creates a new instance of the receiver of the console events that might be read from the given input . It spins up a thread that will read the input forever with no means of stopping it other than closing the input or the receiver . How the input closes depends on its implementation but you can simply drop the receiver . Note that the thread would only close after it goes out of being blocked by receiving some data from the input . The algorithm relies on the fact that it reads individual key presses as separate chunks and when it receives a lot of bytes at once it tries to parse sequences of them checking how many bytes they consumed and storing the excesses ( when receiving events rapidly enough ) for the next iterations
pub fn create_event_receiver<R: Read + Send + 'static>(mut input: R) -> Receiver<io::Result<Event>> {
    let (tx, rx) = crossbeam_channel::unbounded();
    thread::spawn(move || {
        let mut offset = 0;
        // mouse event with both coords >100 takes 13 bytes, max found yet
        let mut buf = [0; 16];
        loop {
            let res = match input.read(&mut buf[offset..]) {
                Ok(bytes_read) => {
                    match bytes_read {
                        0 => break, // 0 bytes read means EOF
                        _ => {
                            let size = bytes_read + offset;
                            let (event, read) = parse_input_sequence(&buf[0..size]);
                            if read < size {
                                // store the unconsumed part as part of the next buffer
                                offset = size - read;
                                buf.copy_within(read..size, 0);
                            } else {
                                offset = 0;
                            }
                            tx.send(Ok(event))
                        }
                    }
                }
                Err(e) if e.kind() == ErrorKind::UnexpectedEof => break,
                Err(e) => tx.send(Err(e)),
            };
            if res.is_err() {
                // SendError only occurs when you close the channel, so we just shut down
                break;
            }
        }
    });
    rx
}
pub fn create_event_receiver < R : Read + Send + ' static > ( mut input : R ) -> Receiver < io :: Result < Event > > { let ( tx , rx ) = crossbeam_channel :: unbounded ( ) ; thread :: spawn ( move | | { let mut offset = 0 ; // mouse event with both coords >100 takes 13 bytes, max found yet let mut buf = [ 0 ; 16 ] ; loop { let res = match input . read ( & mut buf [ offset .. ] ) { Ok ( bytes_read ) => { match bytes_read { 0 => break , // 0 bytes read means EOF _ => { let size = bytes_read + offset ; let ( event , read ) = parse_input_sequence ( & buf [ 0 .. size ] ) ; if read < size { // store the unconsumed part as part of the next buffer offset = size - read ; buf . copy_within ( read .. size , 0 ) ; } else { offset = 0 ; } tx . send ( Ok ( event ) ) } } } Err ( e ) if e . kind ( ) == ErrorKind :: UnexpectedEof => break , Err ( e ) => tx . send ( Err ( e ) ) , } ; if res . is_err ( ) { // SendError only occurs when you close the channel, so we just shut down break ; } } } ) ; rx }
Creates a new instance of the receiver of the console events
that might be read from the given input.
Creates a new instance of the receiver of the console events that might be read from the given input .
input
R
input
R