Handles pseudo-terminal spawning, input injection, and process lifecycle monitoring. Use this for testing terminal-based applications or interactive CLI tools.
// Source: https://github.com/xai-org/grok-build | License: Apache-2.0 | Copyright 2023-2026 SpaceXAI
// Provided via justclaw.it.com; keep this notice with the code.
//! Layer 1: PTY management (spawn, inject keys, resize, drain output).
use std::ffi::OsStr;
use std::io::{self, Read, Write};
use std::path::Path;
use std::sync::mpsc;
use std::time::Duration;
use anyhow::{Context, Result};
use portable_pty::{ExitStatus, PtySize, native_pty_system};
use xai_grok_test_support::{TestProcessTree, TestSandbox, process_has_exited_without_reap};
const PTY_DROP_REAP_TIMEOUT: Duration = Duration::from_millis(250);
/// Grace after group SIGTERM before SIGKILL so a responsive child can run TERM cleanup. Wedged children fall through to SIGKILL.
/// Detached-background reap is the pager quit path, no
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key