init - implement raw mode
This commit is contained in:
commit
6ffb32c543
7 changed files with 210 additions and 0 deletions
23
examples/print.rs
Normal file
23
examples/print.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue