ants/examples/print.rs

24 lines
480 B
Rust
Raw Normal View History

2023-03-19 00:10:08 +01:00
use ants::{event::Events, raw_mode};
use std::{
io::{stdin, Read},
time::{Duration, SystemTime},
};
fn main() {
raw_mode::enter().unwrap();
let start_time = SystemTime::now();
let mut buf = Vec::new();
while start_time.elapsed().unwrap() < Duration::from_secs(5) {
let mut b = [0u8];
if let Ok(_n) = stdin().read(&mut b) {
if b[0] != 0 {
buf.push(b[0]);
print!("[{}]:{}\n\r", b[0], String::from_utf8_lossy(&buf));
}
}
}
raw_mode::exit().unwrap();
}