From a4bca446049fd488af29dd5ec26f953845e8e4fe Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 6 Mar 2021 18:45:50 -0500 Subject: split into sync and async implementations --- examples/async.rs | 29 +++++++++++++++++++++++++++++ examples/basic.rs | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 examples/async.rs (limited to 'examples') diff --git a/examples/async.rs b/examples/async.rs new file mode 100644 index 0000000..e8e4282 --- /dev/null +++ b/examples/async.rs @@ -0,0 +1,29 @@ +use textmode::Textmode as _; + +async fn run(tm: &mut textmode::r#async::Textmode) -> std::io::Result<()> { + tm.move_to(5, 5); + tm.write_str("foo"); + smol::Timer::after(std::time::Duration::from_secs(2)).await; + tm.refresh().await?; + smol::Timer::after(std::time::Duration::from_secs(2)).await; + + tm.move_to(8, 8); + tm.set_fgcolor(textmode::color::GREEN); + tm.write_str("bar"); + tm.move_to(11, 11); + tm.set_fgcolor(vt100::Color::Default); + tm.write_str("baz"); + smol::Timer::after(std::time::Duration::from_secs(2)).await; + tm.refresh().await?; + smol::Timer::after(std::time::Duration::from_secs(2)).await; + Ok(()) +} + +fn main() { + smol::block_on(async { + let mut tm = textmode::r#async::Textmode::new().await.unwrap(); + let e = run(&mut tm).await; + tm.cleanup().await.unwrap(); + e.unwrap(); + }); +} diff --git a/examples/basic.rs b/examples/basic.rs index 1026834..150c9b0 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,5 +1,7 @@ +use textmode::Textmode as _; + fn main() { - let mut tm = textmode::Textmode::new().unwrap(); + let mut tm = textmode::sync::Textmode::new().unwrap(); tm.move_to(5, 5); tm.write_str("foo"); -- cgit v1.2.3-54-g00ecf