Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Control a Shell With pty-shell

Hibariya Hi
December 23, 2015

Control a Shell With pty-shell

Introducing pty-shell which is an extension of pty crate

Hibariya Hi

December 23, 2015
Tweet

More Decks by Hibariya Hi

Other Decks in Technology

Transcript

  1. Control a Shell With pty-shell
    Rust of Us - Chapter 5
    2015-12-23
    @hibariya

    View Slide

  2. Hi, there.
    ● Hika Hibariya
    ● @hibariya
    ● hibariya.org

    View Slide

  3. pty

    View Slide

  4. pty: Fork With a New TTY
    https://github.com/hibariya/pty-rs
    ● pty::fork()
    ● Substitute of PTY.spawn

    View Slide

  5. pty: Fork With a New TTY

    View Slide

  6. It’s Not Enough
    My original purpose is to control STDIO of a
    shell process. To accomplish it, I have to do
    followings.
    ● Do exec a shell command (e.g. bash)
    ● Make parent process enter raw-mode
    ● Connect parent STDIO to child STDIO
    ● Notify winsize changes from parent to child

    View Slide

  7. pty-shell

    View Slide

  8. pty-shell: A Dedicated Extension For Shell

    View Slide

  9. pty-shell: Control STDIO of a Shell
    https://github.com/hibariya/pty-shell
    Spawns a new shell and connects to its parent’
    s STDIO. Then makes the parent act as proxy.
    Anyway, you can hook the INPUT/OUTPUT of
    a shell process. For example: you can play any
    sound effect and/or you can record or share
    output of the terminal.

    View Slide

  10. What To Use?
    For example: Terminal sharing tool
    https://github.com/idobata/hokaido

    View Slide

  11. Do Something On INPUT/OUTPUT

    View Slide

  12. Play Sound Effects

    View Slide

  13. Send Messages

    View Slide

  14. Record It

    View Slide

  15. Anything

    View Slide

  16. use pty;
    use pty_shell::{PtyProxy, PtyHandler};
    struct MyHandler;
    impl PtyHandler for MyHandler {
    fn input(&mut self, input: Vec) {
    // do something with input
    }
    fn output(&mut self, output: Vec) {
    // do something with output
    }
    }

    View Slide

  17. fn main() {
    let child = pty::fork().unwrap();
    child.exec("bash");
    child.proxy(MyHandler);
    child.wait();
    }

    View Slide

  18. extern crate pty_shell;

    View Slide