aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-12 13:04:28 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-12 13:04:28 -0500
commit3ad62c9428e2ca9411f7b993909ce52207871e2d (patch)
treec31cf7a24cbc943b15f316dbffc8bda2f68c5a28
parent15d0610c58e7ee871f8f356a90c99999e0f8a924 (diff)
downloadtextmode-3ad62c9428e2ca9411f7b993909ce52207871e2d.tar.gz
textmode-3ad62c9428e2ca9411f7b993909ce52207871e2d.zip
wait for a key instead of sleeping in examples
-rw-r--r--examples/async.rs16
-rw-r--r--examples/basic.rs9
2 files changed, 15 insertions, 10 deletions
diff --git a/examples/async.rs b/examples/async.rs
index 5102aba..e8c88ba 100644
--- a/examples/async.rs
+++ b/examples/async.rs
@@ -1,11 +1,14 @@
use textmode::Textmode as _;
-async fn run(tm: &mut textmode::Output) -> textmode::Result<()> {
+async fn run(
+ tm: &mut textmode::Output,
+ input: &mut textmode::Input,
+) -> textmode::Result<()> {
tm.move_to(5, 5);
tm.write_str("foo");
- smol::Timer::after(std::time::Duration::from_secs(2)).await;
+ input.read_key().await?;
tm.refresh().await?;
- smol::Timer::after(std::time::Duration::from_secs(2)).await;
+ input.read_key().await?;
tm.move_to(8, 8);
tm.set_fgcolor(textmode::color::GREEN);
@@ -13,16 +16,17 @@ async fn run(tm: &mut textmode::Output) -> textmode::Result<()> {
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;
+ input.read_key().await?;
tm.refresh().await?;
- smol::Timer::after(std::time::Duration::from_secs(2)).await;
+ input.read_key().await?;
Ok(())
}
fn main() {
smol::block_on(async {
let mut tm = textmode::Output::new().await.unwrap();
- let e = run(&mut tm).await;
+ let mut input = textmode::Input::new().await.unwrap();
+ let e = run(&mut tm, &mut input).await;
e.unwrap();
});
}
diff --git a/examples/basic.rs b/examples/basic.rs
index fb13d89..18d86a9 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -2,12 +2,13 @@ use textmode::Textmode as _;
fn main() {
let mut tm = textmode::blocking::Output::new().unwrap();
+ let mut input = textmode::blocking::Input::new().unwrap();
tm.move_to(5, 5);
tm.write_str("foo");
- std::thread::sleep(std::time::Duration::from_secs(2));
+ input.read_key().unwrap();
tm.refresh().unwrap();
- std::thread::sleep(std::time::Duration::from_secs(2));
+ input.read_key().unwrap();
tm.move_to(8, 8);
tm.set_fgcolor(textmode::color::GREEN);
@@ -15,7 +16,7 @@ fn main() {
tm.move_to(11, 11);
tm.set_fgcolor(vt100::Color::Default);
tm.write_str("baz");
- std::thread::sleep(std::time::Duration::from_secs(2));
+ input.read_key().unwrap();
tm.refresh().unwrap();
- std::thread::sleep(std::time::Duration::from_secs(2));
+ input.read_key().unwrap();
}