aboutsummaryrefslogtreecommitdiffstats
path: root/examples/basic.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-13 14:39:14 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-13 14:39:14 -0500
commitf0c07dfee8b65a36033943f888c1da5f8ec96098 (patch)
tree4382c61dc122c639b4cd062abdd42a43b2cc5555 /examples/basic.rs
parent5244bfcd2b67ab6bf808750326de1e08e52c4f2f (diff)
downloadtextmode-f0c07dfee8b65a36033943f888c1da5f8ec96098.tar.gz
textmode-f0c07dfee8b65a36033943f888c1da5f8ec96098.zip
clean up examples to make a bare `cargo test` work
Diffstat (limited to 'examples/basic.rs')
-rw-r--r--examples/basic.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/basic.rs b/examples/basic.rs
index 18d86a9..49f56bc 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -1,5 +1,39 @@
use textmode::Textmode as _;
+#[cfg(feature = "async")]
+async fn run(
+ tm: &mut textmode::Output,
+ input: &mut textmode::Input,
+) -> textmode::Result<()> {
+ tm.move_to(5, 5);
+ tm.write_str("foo");
+ input.read_key().await?;
+ tm.refresh().await?;
+ input.read_key().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");
+ input.read_key().await?;
+ tm.refresh().await?;
+ input.read_key().await?;
+ Ok(())
+}
+
+#[cfg(feature = "async")]
+fn main() {
+ smol::block_on(async {
+ let mut input = textmode::Input::new().await.unwrap();
+ let mut tm = textmode::Output::new().await.unwrap();
+ let e = run(&mut tm, &mut input).await;
+ e.unwrap();
+ });
+}
+
+#[cfg(not(feature = "async"))]
fn main() {
let mut tm = textmode::blocking::Output::new().unwrap();
let mut input = textmode::blocking::Input::new().unwrap();