]> git.proxmox.com Git - rustc.git/blob - src/vendor/termion/examples/async.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / vendor / termion / examples / async.rs
1 extern crate termion;
2
3 use termion::raw::IntoRawMode;
4 use termion::async_stdin;
5 use std::io::{Read, Write, stdout};
6 use std::thread;
7 use std::time::Duration;
8
9 fn main() {
10 let stdout = stdout();
11 let mut stdout = stdout.lock().into_raw_mode().unwrap();
12 let mut stdin = async_stdin().bytes();
13
14 write!(stdout,
15 "{}{}",
16 termion::clear::All,
17 termion::cursor::Goto(1, 1))
18 .unwrap();
19
20 loop {
21 write!(stdout, "{}", termion::clear::CurrentLine).unwrap();
22
23 let b = stdin.next();
24 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();
25 if let Some(Ok(b'q')) = b {
26 break;
27 }
28
29 stdout.flush().unwrap();
30
31 thread::sleep(Duration::from_millis(50));
32 stdout.write_all(b"# ").unwrap();
33 stdout.flush().unwrap();
34 thread::sleep(Duration::from_millis(50));
35 stdout.write_all(b"\r #").unwrap();
36 write!(stdout, "{}", termion::cursor::Goto(1, 1)).unwrap();
37 stdout.flush().unwrap();
38 }
39 }