pub struct Session { /* private fields */ }blocking only.Expand description
A managed blocking pseudoconsole session.
Reading and writing delegate to the session’s output and input streams.
Session::wait drains and discards output concurrently, while
Session::collect_output retains it. Use Session::into_parts for
interactive or externally coordinated I/O.
Dropping an unfinished managed session closes its kill-on-close Job and terminates the root process together with every descendant.
Implementations§
Source§impl Session
impl Session
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
Returns the exit status when the root process has already exited.
§Errors
Returns an error with crate::ErrorKind::Wait if Windows cannot
query the process.
Sourcepub fn kill(&mut self) -> Result<()>
pub fn kill(&mut self) -> Result<()>
Terminates the root process and every descendant in its Job.
§Errors
Returns an error with crate::ErrorKind::Kill if Windows cannot
terminate the Job.
Sourcepub fn resize(&self, size: Size) -> Result<()>
pub fn resize(&self, size: Size) -> Result<()>
Resizes the pseudoconsole.
§Errors
Returns an error with crate::ErrorKind::Resize if the backend
rejects the size, or an std::io::ErrorKind::NotConnected source
after teardown.
Sourcepub fn clear(&self) -> Result<()>
pub fn clear(&self) -> Result<()>
Clears the pseudoconsole screen and scrollback.
§Errors
Returns an error with crate::ErrorKind::UnsupportedFeature when the
backend has no clear operation, crate::ErrorKind::Clear on backend
failure, or an std::io::ErrorKind::NotConnected source after
teardown.
Sourcepub fn supports_clear(&self) -> bool
pub fn supports_clear(&self) -> bool
Returns whether this backend supports clearing the console.
Sourcepub fn wait(self) -> Result<ExitStatus>
pub fn wait(self) -> Result<ExitStatus>
Waits for the root process while draining and discarding VT output.
Output is drained on a dedicated thread, so a child that writes more than the pipe capacity cannot deadlock. Once the root status is saved, remaining descendants are terminated and the teardown tail is drained to EOF without allocating an output-sized buffer.
Terminal input remains open until the root exits. Closing input is session teardown, not an ordinary stdin EOF signal.
§Errors
Returns an error if the reader thread cannot be created, output cannot be drained, the root process status cannot be obtained, or the remaining process tree cannot be terminated.
Sourcepub fn collect_output(self) -> Result<SessionOutput>
pub fn collect_output(self) -> Result<SessionOutput>
Waits for the root process while collecting the remaining VT output.
Collection leaves terminal input open until the root exits, so the
caller must first arrange for the program to finish through its own
protocol. ConPTY has no ordinary stdin half-close: closing its input
is terminal teardown and could replace the real exit status.
Output is drained on a dedicated thread while the root runs. Once its
status is captured, any descendants still in the managed Job are
terminated, terminal input is retired, and the reader drains the
teardown tail to EOF. This gives released and legacy ConPTY backends
the same finite, root-bounded completion rule.
Bytes already read from this Session are not included.
Collection is unbounded and may allocate as much memory as the child
writes. Use Session::wait when output is unnecessary, or
Session::into_parts to process it as a stream.
§Examples
use conpty_oxide::blocking::Command;
let output = Command::new("cmd.exe")
.args(["/d", "/c", "echo", "hello"])
.spawn()?
.collect_output()?;
assert!(output.status().success());
print!("{}", String::from_utf8_lossy(output.as_bytes()));§Errors
Returns an error if the reader thread cannot be created, output cannot be drained, the root process status cannot be obtained, or the remaining process tree cannot be terminated.
Sourcepub fn into_parts(self) -> SessionParts
pub fn into_parts(self) -> SessionParts
Decomposes this session for interactive or externally coordinated I/O.
Splitting changes ownership only: root exit still terminates remaining descendants and advances output to EOF. It does not detach the session.
Trait Implementations§
Source§impl Read for Session
impl Read for Session
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Write for Session
impl Write for Session
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)