Skip to content

Commit

Permalink
fix: work in progress macos support
Browse files Browse the repository at this point in the history
Co-authored-by: alex <[email protected]>
Co-authored-by: echolinq <[email protected]>
Co-authored-by: warren2k <[email protected]>
  • Loading branch information
4 people committed Nov 12, 2023
1 parent 74c223d commit 7889630
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ impl Pty {
/// unable to put it into non-blocking mode.
pub fn new() -> crate::Result<Self> {
let pty = crate::sys::Pty::open()?;
pty.set_nonblocking()?;
Ok(Self(tokio::io::unix::AsyncFd::new(pty)?))
}

Expand All @@ -35,7 +34,9 @@ impl Pty {
/// Returns an error if the device node to open could not be determined,
/// or if the device node could not be opened.
pub fn pts(&self) -> crate::Result<Pts> {
Ok(Pts(self.0.get_ref().pts()?))
let pts = Pts(self.0.get_ref().pts()?);
self.0.get_ref().set_nonblocking()?;
Ok(pts)
}

/// Splits a `Pty` into a read half and a write half, which can be used to
Expand Down
14 changes: 6 additions & 8 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ fn test_cat_blocking() {
use std::io::Write as _;

let mut pty = pty_process::blocking::Pty::new().unwrap();
let pts = pty.pts().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("cat")
.spawn(&pty.pts().unwrap())
.spawn(&pts)
.unwrap();

pty.write_all(b"foo\n").unwrap();
Expand All @@ -16,9 +17,7 @@ fn test_cat_blocking() {
assert_eq!(output.next().unwrap(), "foo\r\n");
assert_eq!(output.next().unwrap(), "foo\r\n");

pty.write_all(&[4u8]).unwrap();
let status = child.wait().unwrap();
assert_eq!(status.code().unwrap(), 0);
child.kill().unwrap();
}

#[cfg(feature = "async")]
Expand All @@ -40,9 +39,7 @@ async fn test_cat_async() {
assert_eq!(output.next().await.unwrap(), "foo\r\n");
assert_eq!(output.next().await.unwrap(), "foo\r\n");

pty_w.write_all(&[4u8]).await.unwrap();
let status = child.wait().await.unwrap();
assert_eq!(status.code().unwrap(), 0);
child.kill().await.unwrap()
}

#[cfg(feature = "async")]
Expand All @@ -68,5 +65,6 @@ async fn test_yes_async() {
let bytes = pty_r.read_buf(&mut &mut buf[..]).await.unwrap();
assert_eq!(&buf[..bytes], b"y\r\n");

child.kill().await.unwrap()
#[cfg(not(target_os = "macos"))]
child.kill().await.unwrap();
}

0 comments on commit 7889630

Please sign in to comment.