An extension of pty crate.
https://speakerdeck.com/hibariya/control-a-shell-with-pty-shell
Add this to your Cargo.toml
:
```toml [dependencies]
pty = '0.1.6' pty-shell = '0.1.3' ```
For example, add src/main.rs as following:
```rust extern crate pty; extern crate pty_shell;
use pty_shell::{winsize, PtyShell, PtyHandler};
struct Shell; impl PtyHandler for Shell { fn input(&mut self, input: &[u8]) { /* do something with input */ }
fn output(&mut self, output: &[u8]) {
/* do something with output */
}
fn resize(&mut self, winsize: &winsize::Winsize) {
/* do something with winsize */
}
fn shutdown(&mut self) {
/* prepare for shutdown */
}
}
fn main() { let child = pty::fork().unwrap();
child.exec("bash");
child.proxy(Shell);
child.wait();
} ```
Use pty_shell::PtyCallback
.
rust
child.proxy(
PtyCallback::new()
.input(|input| { /* do something with input */ })
.output(|output| { /* do something with output */ })
.build()
)
);
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Copyright (c) 2015 Hika Hibariya
Distributed under the MIT License.