1 unstable release

0.1.0 Aug 2, 2023

#13 in #xterm

MIT license

14KB
288 lines

pty-exec

use std::os::fd::{AsRawFd, FromRawFd};
use pty_exec::Pty;

// spawn Pty
let pty = Pty::spawn(move |_fd, res| {
    println!("{}", res.unwrap());
}, move |fd| {
    println!("{fd} died");
})?;

// (optional) create new pty, this maintains the on_read and on_death callbacks
// this means a RawFd can be passed to client like in a tauri app
let pty = unsafe { Pty::from_raw_fd(pty.as_raw_fd()) };

// write to original pty with new pty from_raw_fd
pty.write("echo 'Hello, World'\r")?;

pty.kill();

lib.rs:

use std::os::fd::{AsRawFd, FromRawFd};
use pty_exec::Pty;

// spawn Pty
let pty = Pty::spawn(move |_fd, res| {
    println!("-> {}", res.unwrap());
}, move |fd| {
    println!("-> {fd} died");
})?;

// (optional) create new pty, this maintains the on_read and on_death callbacks
let pty = unsafe { Pty::from_raw_fd(pty.as_raw_fd()) };

// write to original pty with new pty from_raw_fd
pty.write("echo 'Hello, World'\r")?;

pty.kill();

Dependencies

~1.5MB
~35K SLoC