aboutsummaryrefslogtreecommitdiffstats
path: root/examples/async.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-06 18:45:50 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-06 18:45:50 -0500
commita4bca446049fd488af29dd5ec26f953845e8e4fe (patch)
treefa7f129e5b27c00f29b4f33edbc31f2c68d89fda /examples/async.rs
parente358c58826b1732763970848c0c6d77f12ef5e5a (diff)
downloadtextmode-a4bca446049fd488af29dd5ec26f953845e8e4fe.tar.gz
textmode-a4bca446049fd488af29dd5ec26f953845e8e4fe.zip
split into sync and async implementations
Diffstat (limited to 'examples/async.rs')
-rw-r--r--examples/async.rs29
1 files changed, 29 insertions, 0 deletions
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();
+ });
+}