pub struct PtySession { /* private fields */ }Expand description
Async PTY session. Spawns a CLI tool in a real PTY and broadcasts AgentEvent
to all subscribers via a tokio broadcast channel.
The reader loop runs on a blocking thread (via spawn_blocking) because PTY
I/O is inherently blocking. The loop bridges to async consumers via the
broadcast channel.
§Broadcast semantics
tokio::sync::broadcast drops events for lagged receivers — if a subscriber
falls behind, it will skip events. This is acceptable for streaming agent output
(e.g., TUI rendering can re-render from the PTY screen buffer). If you need
guaranteed delivery, wrap the receiver in a buffering layer.
Implementations§
Source§impl PtySession
impl PtySession
Sourcepub async fn spawn(config: SessionConfig) -> Result<Self, AgentError>
pub async fn spawn(config: SessionConfig) -> Result<Self, AgentError>
Spawn a CLI tool in a PTY and start broadcasting events.
Uses a 24x80 terminal size (compact). To control size, use spawn_with_size.
Sourcepub async fn spawn_with_size(
config: SessionConfig,
rows: u16,
cols: u16,
) -> Result<Self, AgentError>
pub async fn spawn_with_size( config: SessionConfig, rows: u16, cols: u16, ) -> Result<Self, AgentError>
Spawn a CLI tool in a PTY with a specific terminal size.
Sourcepub fn subscribe(&self) -> Receiver<AgentEvent>
pub fn subscribe(&self) -> Receiver<AgentEvent>
Subscribe to receive all future AgentEvent values from this session.
Note: events that occurred before subscribing will not be received.
Sourcepub fn write_handle(&self) -> PtyWriteHandle
pub fn write_handle(&self) -> PtyWriteHandle
Get the write handle for sending input to the PTY.
Sourcepub async fn send_prompt(&self, prompt: &str) -> Result<(), AgentError>
pub async fn send_prompt(&self, prompt: &str) -> Result<(), AgentError>
Send a prompt char-by-char (required for Ink-based TUI tools like Claude Code).
Sends each character with a small delay to avoid overwhelming the TUI’s raw-mode input processing. Ends with a carriage return.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Session ID assigned at spawn time.
Sourcepub async fn kill(&self) -> Result<(), AgentError>
pub async fn kill(&self) -> Result<(), AgentError>
Abort the reader task and kill the child process.
Auto Trait Implementations§
impl Freeze for PtySession
impl RefUnwindSafe for PtySession
impl Send for PtySession
impl Sync for PtySession
impl Unpin for PtySession
impl UnsafeUnpin for PtySession
impl UnwindSafe for PtySession
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.