From ae9f6d5c55280336bb130cc1a4bf712b45618eae Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Mar 2021 14:26:46 -0500 Subject: add test example for async input as well --- examples/input.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/examples/input.rs b/examples/input.rs index d478f92..fa9215f 100644 --- a/examples/input.rs +++ b/examples/input.rs @@ -1,3 +1,38 @@ +#[cfg(feature = "async")] +async fn async_main() { + let (mut input, _raw) = textmode::Input::new().await.unwrap(); + for arg in std::env::args().skip(1) { + match arg.as_str() { + "--disable-utf8" => input.parse_utf8(false), + "--disable-ctrl" => input.parse_ctrl(false), + "--disable-meta" => input.parse_meta(false), + "--disable-special-keys" => input.parse_special_keys(false), + "--disable-single" => input.parse_single(false), + _ => panic!("unknown arg {}", arg), + } + } + + loop { + let key = input.read_key().await.unwrap(); + if let Some(key) = key { + print!("{:?}: ", key); + let bytes = key.into_bytes(); + print!("{:?}\r\n", bytes); + if bytes.contains(&3) { + break; + } + } else { + break; + } + } +} + +#[cfg(feature = "async")] +fn main() { + smol::block_on(async { async_main().await }) +} + +#[cfg(not(feature = "async"))] fn main() { let (mut input, _raw) = textmode::blocking::Input::new().unwrap(); for arg in std::env::args().skip(1) { -- cgit v1.2.3-54-g00ecf