Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

pty

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

pty: Fork With a New TTY

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

pty-shell

Slide 8

Slide 8 text

pty-shell: A Dedicated Extension For Shell

Slide 9

Slide 9 text

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.

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Do Something On INPUT/OUTPUT

Slide 12

Slide 12 text

Play Sound Effects

Slide 13

Slide 13 text

Send Messages

Slide 14

Slide 14 text

Record It

Slide 15

Slide 15 text

Anything

Slide 16

Slide 16 text

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 } }

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

extern crate pty_shell;