diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-03-11 14:26:46 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-03-11 14:26:46 -0500 |
commit | ae9f6d5c55280336bb130cc1a4bf712b45618eae (patch) | |
tree | d3c3320453a1a22c67286097c8e08c6afe659e5e | |
parent | 2402ba12ec1680a21989e763b8c45c012c9742f5 (diff) | |
download | textmode-ae9f6d5c55280336bb130cc1a4bf712b45618eae.tar.gz textmode-ae9f6d5c55280336bb130cc1a4bf712b45618eae.zip |
add test example for async input as well
-rw-r--r-- | examples/input.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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) { |