pub struct NativePtyProcess {Show 19 fields
pub argv: Vec<String>,
pub cwd: Option<String>,
pub env: Option<Vec<(String, String)>>,
pub rows: u16,
pub cols: u16,
pub handles: Arc<Mutex<Option<NativePtyHandles>>>,
pub reader: Arc<PtyReadShared>,
pub returncode: Arc<Mutex<Option<i32>>>,
pub input_bytes_total: Arc<AtomicUsize>,
pub newline_events_total: Arc<AtomicUsize>,
pub submit_events_total: Arc<AtomicUsize>,
pub echo: Arc<AtomicBool>,
pub idle_detector: Arc<Mutex<Option<Arc<IdleDetectorCore>>>>,
pub output_bytes_total: Arc<AtomicUsize>,
pub control_churn_bytes_total: Arc<AtomicUsize>,
pub reader_worker: Mutex<Option<JoinHandle<()>>>,
pub terminal_input_relay_stop: Arc<AtomicBool>,
pub terminal_input_relay_active: Arc<AtomicBool>,
pub terminal_input_relay_worker: Mutex<Option<JoinHandle<()>>>,
}Expand description
Re-exported native PTY process and interactive session types. Low-level native pseudo-terminal process wrapper.
The process is configured at construction time and is spawned by
Self::start_impl. Output is collected by a reader thread and exposed
through the chunk-reading methods.
Fields§
§argv: Vec<String>Command argv, including the executable as the first element.
cwd: Option<String>Working directory used when spawning the child, or the current directory.
env: Option<Vec<(String, String)>>Environment overrides passed to the child process.
rows: u16Initial PTY row count.
cols: u16Initial PTY column count.
handles: Arc<Mutex<Option<NativePtyHandles>>>Native PTY handles for the running child, present after start.
reader: Arc<PtyReadShared>Shared reader queue and condition variable for PTY output.
returncode: Arc<Mutex<Option<i32>>>Cached child exit code once the process has exited.
input_bytes_total: Arc<AtomicUsize>Total bytes written to the PTY input stream.
newline_events_total: Arc<AtomicUsize>Count of input writes containing a newline.
submit_events_total: Arc<AtomicUsize>Count of explicit submit events recorded for PTY input.
echo: Arc<AtomicBool>When true, the reader thread writes PTY output to stdout.
idle_detector: Arc<Mutex<Option<Arc<IdleDetectorCore>>>>When set, the reader thread feeds output directly to the idle detector.
output_bytes_total: Arc<AtomicUsize>Visible (non-control) output bytes seen by the reader thread.
control_churn_bytes_total: Arc<AtomicUsize>Control churn bytes (ANSI escapes, BS, CR, DEL) seen by the reader.
reader_worker: Mutex<Option<JoinHandle<()>>>Background worker that drains PTY output into the shared queue.
terminal_input_relay_stop: Arc<AtomicBool>Stop flag observed by the terminal input relay worker.
terminal_input_relay_active: Arc<AtomicBool>Whether the terminal input relay worker is currently active.
terminal_input_relay_worker: Mutex<Option<JoinHandle<()>>>Background worker that forwards local terminal input into the PTY.
Implementations§
Source§impl NativePtyProcess
impl NativePtyProcess
Sourcepub fn new(
argv: Vec<String>,
cwd: Option<String>,
env: Option<Vec<(String, String)>>,
rows: u16,
cols: u16,
nice: Option<i32>,
) -> Result<Self, PtyError>
pub fn new( argv: Vec<String>, cwd: Option<String>, env: Option<Vec<(String, String)>>, rows: u16, cols: u16, nice: Option<i32>, ) -> Result<Self, PtyError>
Create a pseudo-terminal process configuration.
The child is not spawned until Self::start_impl is called.
Sourcepub fn mark_reader_closed(&self)
pub fn mark_reader_closed(&self)
Mark the reader stream closed and wake all waiting readers.
Sourcepub fn store_returncode(&self, code: i32)
pub fn store_returncode(&self, code: i32)
Store the process return code if it has been observed.
Sourcepub fn record_input_metrics(&self, data: &[u8], submit: bool)
pub fn record_input_metrics(&self, data: &[u8], submit: bool)
Record PTY input byte, newline, and submit counters.
Sourcepub fn write_impl(&self, data: &[u8], submit: bool) -> Result<(), PtyError>
pub fn write_impl(&self, data: &[u8], submit: bool) -> Result<(), PtyError>
Write bytes to the PTY input stream and record input metrics.
Sourcepub fn request_terminal_input_relay_stop(&self)
pub fn request_terminal_input_relay_stop(&self)
Signal the terminal input relay worker to stop.
Sourcepub fn start_terminal_input_relay_impl(&self) -> Result<(), PtyError>
pub fn start_terminal_input_relay_impl(&self) -> Result<(), PtyError>
Start forwarding local terminal input into the PTY.
Sourcepub fn stop_terminal_input_relay_impl(&self)
pub fn stop_terminal_input_relay_impl(&self)
Stop the terminal input relay worker and wait for it to exit.
Sourcepub fn terminal_input_relay_active(&self) -> bool
pub fn terminal_input_relay_active(&self) -> bool
Return whether the terminal input relay worker is active.
Sourcepub fn close_impl(&self) -> Result<(), PtyError>
pub fn close_impl(&self) -> Result<(), PtyError>
Synchronously tear down the PTY and reap the child.
Sourcepub fn close_nonblocking(&self)
pub fn close_nonblocking(&self)
Best-effort, non-blocking teardown for use from Drop.
Sourcepub fn start_impl(&self) -> Result<(), PtyError>
pub fn start_impl(&self) -> Result<(), PtyError>
Spawn the configured child process inside a native PTY.
Sourcepub fn respond_to_queries_impl(&self, data: &[u8]) -> Result<(), PtyError>
pub fn respond_to_queries_impl(&self, data: &[u8]) -> Result<(), PtyError>
Respond to terminal query escape sequences found in a PTY output chunk.
Sourcepub fn resize_impl(&self, rows: u16, cols: u16) -> Result<(), PtyError>
pub fn resize_impl(&self, rows: u16, cols: u16) -> Result<(), PtyError>
Resize the PTY to the given row and column dimensions.
Sourcepub fn send_interrupt_impl(&self) -> Result<(), PtyError>
pub fn send_interrupt_impl(&self) -> Result<(), PtyError>
Send an interrupt signal or control event to the PTY child.
Sourcepub fn wait_impl(&self, timeout: Option<f64>) -> Result<i32, PtyError>
pub fn wait_impl(&self, timeout: Option<f64>) -> Result<i32, PtyError>
Wait for the PTY child to exit and return its exit code.
Returns a timeout error when timeout elapses before exit.
Sourcepub fn terminate_impl(&self) -> Result<(), PtyError>
pub fn terminate_impl(&self) -> Result<(), PtyError>
Request graceful termination of the PTY child.
Sourcepub fn terminate_tree_impl(&self) -> Result<(), PtyError>
pub fn terminate_tree_impl(&self) -> Result<(), PtyError>
Request graceful termination of the PTY child process tree.
Sourcepub fn kill_tree_impl(&self) -> Result<(), PtyError>
pub fn kill_tree_impl(&self) -> Result<(), PtyError>
Forcefully terminate the PTY child process tree.
Sourcepub fn pid(&self) -> Result<Option<u32>, PtyError>
pub fn pid(&self) -> Result<Option<u32>, PtyError>
Get the PID of the child process, if running.
Sourcepub fn read_chunk_impl(
&self,
timeout: Option<f64>,
) -> Result<Option<Vec<u8>>, PtyError>
pub fn read_chunk_impl( &self, timeout: Option<f64>, ) -> Result<Option<Vec<u8>>, PtyError>
Wait for a chunk of output from the PTY reader.
Returns Ok(Some(chunk)) on data, Ok(None) on timeout, Err on closed.
Sourcepub fn wait_for_reader_closed_impl(&self, timeout: Option<f64>) -> bool
pub fn wait_for_reader_closed_impl(&self, timeout: Option<f64>) -> bool
Wait for the reader thread to close.
Sourcepub fn wait_and_drain_impl(
&self,
timeout: Option<f64>,
drain_timeout: f64,
) -> Result<i32, PtyError>
pub fn wait_and_drain_impl( &self, timeout: Option<f64>, drain_timeout: f64, ) -> Result<i32, PtyError>
Wait for exit then drain remaining output.
Sourcepub fn echo_enabled(&self) -> bool
pub fn echo_enabled(&self) -> bool
Return whether PTY output echoing is enabled.
Sourcepub fn attach_idle_detector(&self, detector: &Arc<IdleDetectorCore>)
pub fn attach_idle_detector(&self, detector: &Arc<IdleDetectorCore>)
Attach an idle detector that observes reader-thread output.
Sourcepub fn detach_idle_detector(&self)
pub fn detach_idle_detector(&self)
Detach the current idle detector, if one is attached.
Sourcepub fn pty_input_bytes_total(&self) -> usize
pub fn pty_input_bytes_total(&self) -> usize
Return total bytes written to PTY input.
Sourcepub fn pty_newline_events_total(&self) -> usize
pub fn pty_newline_events_total(&self) -> usize
Return the number of PTY input writes containing newlines.
Sourcepub fn pty_submit_events_total(&self) -> usize
pub fn pty_submit_events_total(&self) -> usize
Return the number of recorded PTY input submit events.
Sourcepub fn pty_output_bytes_total(&self) -> usize
pub fn pty_output_bytes_total(&self) -> usize
Return visible PTY output bytes observed by the reader thread.
Sourcepub fn pty_control_churn_bytes_total(&self) -> usize
pub fn pty_control_churn_bytes_total(&self) -> usize
Return control-churn bytes observed by the reader thread.
Trait Implementations§
Source§impl Drop for NativePtyProcess
impl Drop for NativePtyProcess
Auto Trait Implementations§
impl !Freeze for NativePtyProcess
impl RefUnwindSafe for NativePtyProcess
impl Send for NativePtyProcess
impl Sync for NativePtyProcess
impl Unpin for NativePtyProcess
impl UnsafeUnpin for NativePtyProcess
impl UnwindSafe for NativePtyProcess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more