pub struct PtyExecutor { /* private fields */ }Expand description
Executor for running prompts in a pseudo-terminal.
Implementations§
Source§impl PtyExecutor
impl PtyExecutor
Sourcepub fn new(backend: CliBackend, config: PtyConfig) -> Self
pub fn new(backend: CliBackend, config: PtyConfig) -> Self
Creates a new PTY executor with the given backend and configuration.
Sourcepub fn set_tui_mode(&mut self, enabled: bool)
pub fn set_tui_mode(&mut self, enabled: bool)
Sets the TUI mode flag.
When TUI mode is enabled, PTY output is sent to the TUI channel instead of being written directly to stdout. This flag must be set before calling any of the run methods when using the TUI.
§Arguments
enabled- Whether TUI mode should be active
Sourcepub fn set_backend(&mut self, backend: CliBackend)
pub fn set_backend(&mut self, backend: CliBackend)
Updates the backend configuration for this executor.
This allows switching backends between iterations without recreating the entire executor. Critical for hat-level backend configuration support.
§Arguments
backend- The new backend configuration to use
Sourcepub fn handle(&mut self) -> PtyHandle
pub fn handle(&mut self) -> PtyHandle
Returns a handle for TUI integration.
Can only be called once - panics if called multiple times.
Sourcepub async fn run_observe(
&self,
prompt: &str,
interrupt_rx: Receiver<bool>,
) -> Result<PtyExecutionResult>
pub async fn run_observe( &self, prompt: &str, interrupt_rx: Receiver<bool>, ) -> Result<PtyExecutionResult>
Runs in observe mode (output-only, no input forwarding).
This is an async function that listens for interrupt signals via the shared
interrupt_rx watch channel from the event loop.
Uses a separate thread for blocking PTY reads and tokio::select! for signal handling.
Returns when the process exits, idle timeout triggers, or interrupt is received.
§Arguments
prompt- The prompt to executeinterrupt_rx- Watch channel receiver for interrupt signals from the event loop
§Errors
Returns an error if PTY allocation fails, the command cannot be spawned, or an I/O error occurs during output handling.
Sourcepub async fn run_observe_streaming<H: StreamHandler>(
&self,
prompt: &str,
interrupt_rx: Receiver<bool>,
handler: &mut H,
) -> Result<PtyExecutionResult>
pub async fn run_observe_streaming<H: StreamHandler>( &self, prompt: &str, interrupt_rx: Receiver<bool>, handler: &mut H, ) -> Result<PtyExecutionResult>
Runs in observe mode with streaming event handling for JSON output.
When the backend’s output format is StreamJson, this method parses
NDJSON lines and dispatches events to the provided handler for real-time
display. For Text format, behaves identically to run_observe.
§Arguments
prompt- The prompt to executeinterrupt_rx- Watch channel receiver for interrupt signalshandler- Handler to receive streaming events
§Errors
Returns an error if PTY allocation fails, the command cannot be spawned, or an I/O error occurs during output handling.
Sourcepub async fn run_interactive(
&mut self,
prompt: &str,
interrupt_rx: Receiver<bool>,
) -> Result<PtyExecutionResult>
pub async fn run_interactive( &mut self, prompt: &str, interrupt_rx: Receiver<bool>, ) -> Result<PtyExecutionResult>
Runs in interactive mode (bidirectional I/O).
Uses tokio::select! for non-blocking I/O multiplexing between:
- PTY output (from blocking reader via channel)
- User input (from stdin thread via channel)
- Interrupt signal from event loop
- Idle timeout
This design ensures Ctrl+C is always responsive, even when the PTY has no output (e.g., during long-running tool calls).
§Arguments
prompt- The prompt to executeinterrupt_rx- Watch channel receiver for interrupt signals from the event loop
§Errors
Returns an error if PTY allocation fails, the command cannot be spawned, or an I/O error occurs during bidirectional communication.
Auto Trait Implementations§
impl Freeze for PtyExecutor
impl !RefUnwindSafe for PtyExecutor
impl Send for PtyExecutor
impl Sync for PtyExecutor
impl Unpin for PtyExecutor
impl UnsafeUnpin for PtyExecutor
impl !UnwindSafe for PtyExecutor
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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