fn spawn_stdin_channel() -> Receiver<char> {
    let (tx, rx) = mpsc::channel::<char>();
    thread::spawn(move || loop {
        let mut byte: [u8; 1] = [0];
        let mut buf: [u8; 4] = [0; 4];
        let mut i = 0;
        loop {
            io::stdin().read_exact(&mut byte).unwrap();
            buf[i] = byte[0];
            if let Ok(s) = std::str::from_utf8(&buf[0..i + 1]) {
                tx.send(s.chars().next().unwrap()).unwrap();
                break;
            }
            i += 1;
        }
    });
    rx
}
// Create a way to read chars from stdin without blocking.
Create a way to read chars from stdin without blocking.
Create a way to read chars from stdin without blocking .
fn spawn_stdin_channel() -> Receiver<char> {
    let (tx, rx) = mpsc::channel::<char>();
    thread::spawn(move || loop {
        let mut byte: [u8; 1] = [0];
        let mut buf: [u8; 4] = [0; 4];
        let mut i = 0;
        loop {
            io::stdin().read_exact(&mut byte).unwrap();
            buf[i] = byte[0];
            if let Ok(s) = std::str::from_utf8(&buf[0..i + 1]) {
                tx.send(s.chars().next().unwrap()).unwrap();
                break;
            }
            i += 1;
        }
    });
    rx
}
fn spawn_stdin_channel ( ) -> Receiver < char > { let ( tx , rx ) = mpsc :: channel :: < char > ( ) ; thread :: spawn ( move | | loop { let mut byte : [ u8 ; 1 ] = [ 0 ] ; let mut buf : [ u8 ; 4 ] = [ 0 ; 4 ] ; let mut i = 0 ; loop { io :: stdin ( ) . read_exact ( & mut byte ) . unwrap ( ) ; buf [ i ] = byte [ 0 ] ; if let Ok ( s ) = std :: str :: from_utf8 ( & buf [ 0 .. i + 1 ] ) { tx . send ( s . chars ( ) . next ( ) . unwrap ( ) ) . unwrap ( ) ; break ; } i += 1 ; } } ) ; rx }
Create a way to read chars from stdin without blocking.
Create a way to read chars from stdin without blocking .