Skip to main content

NativePtyProcess

Struct NativePtyProcess 

Source
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: u16

Initial PTY row count.

§cols: u16

Initial 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

Source

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.

Source

pub fn mark_reader_closed(&self)

Mark the reader stream closed and wake all waiting readers.

Source

pub fn store_returncode(&self, code: i32)

Store the process return code if it has been observed.

Source

pub fn record_input_metrics(&self, data: &[u8], submit: bool)

Record PTY input byte, newline, and submit counters.

Source

pub fn write_impl(&self, data: &[u8], submit: bool) -> Result<(), PtyError>

Write bytes to the PTY input stream and record input metrics.

Source

pub fn request_terminal_input_relay_stop(&self)

Signal the terminal input relay worker to stop.

Source

pub fn start_terminal_input_relay_impl(&self) -> Result<(), PtyError>

Start forwarding local terminal input into the PTY.

Source

pub fn stop_terminal_input_relay_impl(&self)

Stop the terminal input relay worker and wait for it to exit.

Source

pub fn terminal_input_relay_active(&self) -> bool

Return whether the terminal input relay worker is active.

Source

pub fn close_impl(&self) -> Result<(), PtyError>

Synchronously tear down the PTY and reap the child.

Source

pub fn close_nonblocking(&self)

Best-effort, non-blocking teardown for use from Drop.

Source

pub fn start_impl(&self) -> Result<(), PtyError>

Spawn the configured child process inside a native PTY.

Source

pub fn respond_to_queries_impl(&self, data: &[u8]) -> Result<(), PtyError>

Respond to terminal query escape sequences found in a PTY output chunk.

Source

pub fn resize_impl(&self, rows: u16, cols: u16) -> Result<(), PtyError>

Resize the PTY to the given row and column dimensions.

Source

pub fn send_interrupt_impl(&self) -> Result<(), PtyError>

Send an interrupt signal or control event to the PTY child.

Source

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.

Source

pub fn terminate_impl(&self) -> Result<(), PtyError>

Request graceful termination of the PTY child.

Source

pub fn kill_impl(&self) -> Result<(), PtyError>

Forcefully terminate the PTY child.

Source

pub fn terminate_tree_impl(&self) -> Result<(), PtyError>

Request graceful termination of the PTY child process tree.

Source

pub fn kill_tree_impl(&self) -> Result<(), PtyError>

Forcefully terminate the PTY child process tree.

Source

pub fn pid(&self) -> Result<Option<u32>, PtyError>

Get the PID of the child process, if running.

Source

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.

Source

pub fn wait_for_reader_closed_impl(&self, timeout: Option<f64>) -> bool

Wait for the reader thread to close.

Source

pub fn wait_and_drain_impl( &self, timeout: Option<f64>, drain_timeout: f64, ) -> Result<i32, PtyError>

Wait for exit then drain remaining output.

Source

pub fn set_echo(&self, enabled: bool)

Enable or disable echoing PTY output to stdout.

Source

pub fn echo_enabled(&self) -> bool

Return whether PTY output echoing is enabled.

Source

pub fn attach_idle_detector(&self, detector: &Arc<IdleDetectorCore>)

Attach an idle detector that observes reader-thread output.

Source

pub fn detach_idle_detector(&self)

Detach the current idle detector, if one is attached.

Source

pub fn pty_input_bytes_total(&self) -> usize

Return total bytes written to PTY input.

Source

pub fn pty_newline_events_total(&self) -> usize

Return the number of PTY input writes containing newlines.

Source

pub fn pty_submit_events_total(&self) -> usize

Return the number of recorded PTY input submit events.

Source

pub fn pty_output_bytes_total(&self) -> usize

Return visible PTY output bytes observed by the reader thread.

Source

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.