1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! # PTY Module - Pseudo-Terminal Integration
//!
//! This module provides cross-platform pseudo-terminal (PTY) functionality for
//! streaming GPU-accelerated output to terminal emulators. It enables Perdix to
//! act as a transparent layer between AI assistants and terminal applications.
//!
//! ## Purpose
//!
//! PTYs allow Perdix to:
//! - Route AI output through GPU acceleration to terminals
//! - Preserve ANSI formatting and control sequences
//! - Support interactive terminal applications
//! - Provide cross-platform terminal emulation
//!
//! ## Architecture
//!
//! ```text
//! ┌────────────────┐
//! │ AI Assistants │
//! └────────┬───────┘
//! │
//! ▼ GPU writes
//! ┌────────────────┐
//! │ Ring Buffer │ Zero-copy GPU→CPU
//! └────────┬───────┘
//! │
//! ▼ Consumer reads
//! ┌────────────────┐
//! │ PTY Writer │ This module
//! └────────┬───────┘
//! │
//! ▼ Writes to PTY
//! ┌────────────────┐
//! │ Terminal │
//! └────────────────┘
//! ```
//!
//! ## Features
//!
//! - **Cross-Platform**: Works on Windows, Linux, macOS
//! - **ANSI Support**: Preserves colors and formatting
//! - **Async Operation**: Non-blocking PTY I/O
//! - **Process Management**: Spawns and manages shell processes
//!
//! ## Usage
//!
//! ```rust,no_run
//! use perdix::pty::portable::PortablePtyWriter;
//! use perdix::Buffer;
//!
//! // Create buffer and get consumer
//! let buffer = Buffer::new(1024)?;
//! let (_, consumer) = buffer.split();
//!
//! // Create PTY and start writer thread
//! let pty = PortablePtyWriter::new()?;
//! let (stop_flag, handle) = pty.start_writer_thread(consumer);
//!
//! // ... GPU produces messages ...
//!
//! // Stop PTY writer
//! stop_flag.store(true, std::sync::atomic::Ordering::Relaxed);
//! handle.join().unwrap();
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```