summaryrefslogtreecommitdiff
path: root/src/engines.rs
blob: fdf50470dc0bdaed48c36e468f9b51802beb8561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::net::TcpStream;
use termion::raw::IntoRawMode;
use termion::async_stdin;
use std::thread::sleep;
use std::io::{Read, Write, stdout};
use std::time::Duration;

pub fn Engines(mut stream : TcpStream) {
    let stdout = stdout();
    let mut stdout = stdout.lock().into_raw_mode().unwrap();
    let mut stdin = async_stdin().bytes();

    loop {
        match stdin.next() {
            Some(c) => {
                let c = c.unwrap();
                let mut send = String::new();
                send.push(c as char);
                if send.as_bytes() == b"q" {
                    break;
                }
                send.push_str("\n");
                stream.write(send.as_bytes());
            }
            None => ()
        }

        stdout.flush().unwrap();
        sleep(Duration::from_millis(100));
    }
}