diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-24 15:25:25 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-24 15:25:38 -0400 |
commit | 3881362830012ee6408b6b2b7799a07e8230badf (patch) | |
tree | 447f775b34f6e0459388746e75f524ea0bfe44b8 | |
parent | 894ec4f24c1269166f14c05b2ae3f737f76dd571 (diff) | |
download | tokio-pty-process-stream-3881362830012ee6408b6b2b7799a07e8230badf.tar.gz tokio-pty-process-stream-3881362830012ee6408b6b2b7799a07e8230badf.zip |
metadata0.1.0
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | LICENSE | 32 | ||||
-rw-r--r-- | README.md | 55 | ||||
-rw-r--r-- | src/lib.rs | 3 |
4 files changed, 97 insertions, 0 deletions
@@ -4,6 +4,13 @@ version = "0.1.0" authors = ["Jesse Luehrs <doy@tozt.net>"] edition = "2018" +description = "wraps tokio-pty-process in order to provide a simpler API as a single stream object" +license = "MIT" +repository = "https://git.tozt.net/tokio-pty-process-stream" +readme = "README.md" +keywords = ["pty", "futures"] +categories = ["asynchronous"] + [dependencies] component-future = "0.1" futures = "0.1" @@ -0,0 +1,32 @@ +This software is Copyright (c) 2019 by Jesse Luehrs. + +This is free software, licensed under: + + The MIT (X11) License + +The MIT License + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to +whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall +be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT +WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9770430 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# tokio-pty-process-stream + +This crate wraps `tokio-pty-process` in order to provide a simpler API as +a single stream object. + +## Overview + +When you need to interact with an interactive program as part of an +asynchronous application, it can be tricky to figure out the way to +structure the different parts that are required. This crate simplifies the +API down to just providing the input via an `AsyncRead` object, and then +getting updates about what the program is doing via results generated by a +stream. + +## Synopsis + +This is an example of how to run an interactive program and have it behave +identically to running it in the shell. Note that we have to use our own +`Stdin` implementation here because `tokio::io::stdin()` is actually +blocking, and so polling it as part of an interactive application doesn't +work correctly. The implementation of `Stdin` is elided here, but you can +see the full implementation in `examples/shell.rs` in the repository. + +```rust +let mut argv = std::env::args(); +argv.next().unwrap(); +let cmd = argv.next().unwrap(); +let args: Vec<_> = argv.collect(); + +let process = + tokio_pty_process_stream::Process::new(&cmd, &args, Stdin::new()); + +let _raw = crossterm::RawScreen::into_raw_mode().unwrap(); +tokio::run( + process + .for_each(|ev| { + match ev { + tokio_pty_process_stream::Event::CommandStart { + .. + } => {} + tokio_pty_process_stream::Event::Output { data } => { + let stdout = std::io::stdout(); + let mut stdout = stdout.lock(); + stdout.write_all(&data).unwrap(); + stdout.flush().unwrap(); + } + tokio_pty_process_stream::Event::CommandExit { + .. + } => {} + } + futures::future::ok(()) + }) + .map_err(|e| panic!(e)), +); +``` @@ -138,9 +138,12 @@ //! # } //! ``` +// XXX this is broken with ale +// #![warn(clippy::cargo)] #![warn(clippy::pedantic)] #![warn(clippy::nursery)] #![allow(clippy::missing_const_for_fn)] +#![allow(clippy::multiple_crate_versions)] #![allow(clippy::type_complexity)] use futures::future::Future as _; |