Skip to main content

ralph_adapters/
pty_handle.rs

1//! PTY handle abstraction for TUI integration.
2//!
3//! Provides a channel-based interface for bidirectional communication with a PTY.
4//! The TUI can send input and control commands while receiving output asynchronously.
5
6use tokio::sync::{mpsc, watch};
7
8/// Handle for communicating with a PTY process.
9pub struct PtyHandle {
10    /// Receives output from the PTY.
11    pub output_rx: mpsc::UnboundedReceiver<Vec<u8>>,
12    /// Sends input to the PTY.
13    pub input_tx: mpsc::UnboundedSender<Vec<u8>>,
14    /// Sends control commands to the PTY.
15    pub control_tx: mpsc::UnboundedSender<ControlCommand>,
16    /// Signals when the PTY process has terminated.
17    /// TUI should exit when this becomes `true`.
18    pub terminated_rx: watch::Receiver<bool>,
19}
20
21/// Control commands for PTY management.
22#[derive(Debug, Clone)]
23pub enum ControlCommand {
24    /// Resize the PTY to the given (cols, rows).
25    Resize(u16, u16),
26    /// Terminate the PTY process.
27    Kill,
28    /// Skip current iteration.
29    Skip,
30    /// Abort the loop.
31    Abort,
32}