fixed examples
This commit is contained in:
parent
1a64a21df2
commit
1499763054
@ -27,7 +27,7 @@ use crossterm::raw::IntoRawMode;
|
|||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
async_input::read_async();
|
async_input::read_async_until();
|
||||||
}
|
}
|
||||||
|
|
||||||
use crossterm::raw::RawTerminal;
|
use crossterm::raw::RawTerminal;
|
||||||
|
@ -13,12 +13,19 @@ use std::time::Duration;
|
|||||||
|
|
||||||
/// this will capture the input until the given key.
|
/// this will capture the input until the given key.
|
||||||
pub fn read_async_until() {
|
pub fn read_async_until() {
|
||||||
let context = Context::new();
|
let crossterm = Crossterm::new();
|
||||||
let input = input(&context);
|
|
||||||
|
|
||||||
|
// 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();
|
let mut stdin = input.read_until_async(b'\r').bytes();
|
||||||
|
|
||||||
for i in 0..100 {
|
for i in 0..100 {
|
||||||
|
terminal.clear(ClearType::All);
|
||||||
|
cursor.goto(1, 1);
|
||||||
let a = stdin.next();
|
let a = stdin.next();
|
||||||
|
|
||||||
println!("pressed key: {:?}", a);
|
println!("pressed key: {:?}", a);
|
||||||
@ -33,7 +40,7 @@ pub fn read_async_until() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(time::Duration::from_millis(50));
|
thread::sleep(time::Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user