fune/third_party/rust/termion/examples/async.rs
Nathan Froyd 65e7b0bbd1 Bug 1485409 - update crates to dispense with winapi 0.2.8 requirement; r=glandium
winapi 0.2.8 is used by a number of crates in our dependency graph.  The
newest version of winapi is 0.3.4, which is a significant restructuring
and also more amenable to further development, e.g. adding AArch64
support.  This patch does the easy work of updating as many things as
possible to winapi 0.3.4 via a simple `cargo update`:

cargo update -p atty:0.2.2 -p fs2 -p msdos_time -p parking_lot_core -p aho-corasick

and then vendoring the results of those changes.
2018-08-28 21:37:30 -04:00

39 lines
1.1 KiB
Rust

extern crate termion;
use termion::raw::IntoRawMode;
use termion::async_stdin;
use std::io::{Read, Write, stdout};
use std::thread;
use std::time::Duration;
fn main() {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
write!(stdout,
"{}{}",
termion::clear::All,
termion::cursor::Goto(1, 1))
.unwrap();
loop {
write!(stdout, "{}", termion::clear::CurrentLine).unwrap();
let b = stdin.next();
write!(stdout, "\r{:?} <- This demonstrates the async read input char. Between each update a 100 ms. is waited, simply to demonstrate the async fashion. \n\r", b).unwrap();
if let Some(Ok(b'q')) = b {
break;
}
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write_all(b"# ").unwrap();
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write_all(b"\r #").unwrap();
write!(stdout, "{}", termion::cursor::Goto(1, 1)).unwrap();
stdout.flush().unwrap();
}
}