]>
git.proxmox.com Git - rustc.git/blob - vendor/termion/examples/async.rs
3 use termion
:: raw
:: IntoRawMode
;
4 use termion
:: async_stdin
;
5 use std
:: io
:: {Read, Write, stdout}
;
7 use std
:: time
:: Duration
;
10 let stdout
= stdout ();
11 let mut stdout
= stdout
. lock (). into_raw_mode (). unwrap ();
12 let mut stdin
= async_stdin (). bytes ();
17 termion
:: cursor
:: Goto ( 1 , 1 ))
21 write
!( stdout
, " {} " , termion
:: clear
:: CurrentLine
). unwrap ();
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
{
29 stdout
. flush (). unwrap ();
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 ();