aboutsummaryrefslogtreecommitdiffstats
path: root/examples/async-std.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-02-22 17:02:12 -0500
committerJesse Luehrs <doy@tozt.net>2022-02-23 02:44:18 -0500
commit39287b07f87aba15c4cb0f64d7008ba67289151d (patch)
treea0ce5fee6e98a7c429f668000d7cdc71cf8d4797 /examples/async-std.rs
parentebcf5f15081f6a84c861eb2aecbf962396a88695 (diff)
downloadpty-process-39287b07f87aba15c4cb0f64d7008ba67289151d.tar.gz
pty-process-39287b07f87aba15c4cb0f64d7008ba67289151d.zip
another rewrite
Diffstat (limited to 'examples/async-std.rs')
-rw-r--r--examples/async-std.rs85
1 files changed, 0 insertions, 85 deletions
diff --git a/examples/async-std.rs b/examples/async-std.rs
deleted file mode 100644
index 970841c..0000000
--- a/examples/async-std.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-mod raw_guard;
-
-#[cfg(feature = "async")]
-mod main {
- use async_std::io::prelude::WriteExt as _;
- use async_std::io::ReadExt as _;
- use async_std::prelude::FutureExt as _;
-
- pub async fn run(
- child: &async_process::Child,
- pty: &pty_process::Pty,
- ) -> std::result::Result<(), Box<dyn std::error::Error + 'static>> {
- let _raw = super::raw_guard::RawGuard::new();
-
- let mut input_pty = pty;
- let mut output_pty = pty;
- let ex = async_executor::Executor::new();
-
- let input = ex.spawn(async {
- let mut buf = [0_u8; 4096];
- let mut stdin = async_std::io::stdin();
- loop {
- match stdin.read(&mut buf).await {
- Ok(bytes) => {
- input_pty.write_all(&buf[..bytes]).await.unwrap();
- }
- Err(e) => {
- eprintln!("stdin read failed: {:?}", e);
- break;
- }
- }
- }
- });
- let output = ex.spawn(async {
- let mut buf = [0_u8; 4096];
- let mut stdout = async_std::io::stdout();
- loop {
- match output_pty.read(&mut buf).await {
- Ok(bytes) => {
- stdout.write_all(&buf[..bytes]).await.unwrap();
- stdout.flush().await.unwrap();
- }
- Err(e) => {
- eprintln!("pty read failed: {:?}", e);
- break;
- }
- }
- }
- });
-
- let wait = async {
- child.status_no_drop().await.unwrap();
- };
-
- ex.run(input.race(output).race(wait)).await;
-
- Ok(())
- }
-}
-
-#[cfg(feature = "async")]
-fn main() {
- use std::os::unix::process::ExitStatusExt as _;
-
- let status = async_std::task::block_on(async {
- let pty = pty_process::Pty::new().unwrap();
- pty.resize(pty_process::Size::new(24, 80)).unwrap();
- let mut child = pty_process::Command::new("tac")
- // .args(&["500"])
- .spawn(&pty)
- .unwrap();
- main::run(&child, &pty).await.unwrap();
- child.status().await.unwrap()
- });
- std::process::exit(
- status
- .code()
- .unwrap_or_else(|| status.signal().unwrap_or(0) + 128),
- );
-}
-
-#[cfg(not(feature = "async"))]
-fn main() {
- unimplemented!()
-}