fixed examples

This commit is contained in:
Timon 2018-07-26 16:37:36 +00:00
parent 1a64a21df2
commit 1499763054
2 changed files with 11 additions and 4 deletions

View File

@ -27,7 +27,7 @@ use crossterm::raw::IntoRawMode;
use std::{thread, time};
fn main() {
async_input::read_async();
async_input::read_async_until();
}
use crossterm::raw::RawTerminal;

View File

@ -13,12 +13,19 @@ use std::time::Duration;
/// this will capture the input until the given key.
pub fn read_async_until() {
let context = Context::new();
let input = input(&context);
let crossterm = Crossterm::new();
// init some modules we use for this demo
let input = crossterm.input();
let terminal = crossterm.terminal();
let mut cursor = crossterm.cursor();
let mut stdout = stdout().into_raw_mode(crossterm.context()).unwrap();
let mut stdin = input.read_until_async(b'\r').bytes();
for i in 0..100 {
terminal.clear(ClearType::All);
cursor.goto(1, 1);
let a = stdin.next();
println!("pressed key: {:?}", a);
@ -33,7 +40,7 @@ pub fn read_async_until() {
break;
}
thread::sleep(time::Duration::from_millis(50));
thread::sleep(time::Duration::from_millis(100));
}
}