pty_process/blocking/
pty.rspub fn open() -> crate::Result<(Pty, Pts)> {
let pty = crate::sys::Pty::open()?;
let pts = pty.pts()?;
Ok((Pty(pty), Pts(pts)))
}
pub struct Pty(crate::sys::Pty);
impl Pty {
#[must_use]
pub unsafe fn from_fd(fd: std::os::fd::OwnedFd) -> Self {
Self(crate::sys::Pty::from_fd(fd))
}
pub fn resize(&self, size: crate::Size) -> crate::Result<()> {
self.0.set_term_size(size)
}
}
impl From<Pty> for std::os::fd::OwnedFd {
fn from(pty: Pty) -> Self {
pty.0.into()
}
}
impl std::os::fd::AsFd for Pty {
fn as_fd(&self) -> std::os::fd::BorrowedFd<'_> {
self.0.as_fd()
}
}
impl std::os::fd::AsRawFd for Pty {
fn as_raw_fd(&self) -> std::os::fd::RawFd {
self.0.as_raw_fd()
}
}
impl std::io::Read for Pty {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
self.0.read(buf)
}
}
impl std::io::Write for Pty {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
self.0.flush()
}
}
impl std::io::Read for &Pty {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
(&self.0).read(buf)
}
}
impl std::io::Write for &Pty {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
(&self.0).write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
(&self.0).flush()
}
}
pub struct Pts(pub(crate) crate::sys::Pts);
impl Pts {
#[must_use]
pub unsafe fn from_fd(fd: std::os::fd::OwnedFd) -> Self {
Self(crate::sys::Pts::from_fd(fd))
}
}