rust_expect/
lib.rs

1//! rust-expect: Next-generation terminal automation library
2//!
3//! This crate provides an Expect-style API for automating interactive terminal applications.
4//! It supports local PTY sessions, SSH connections, and mock sessions for testing.
5//!
6//! # Features
7//!
8//! - **Async-first design** with Tokio runtime
9//! - **Cross-platform PTY support** via `rust-pty`
10//! - **Flexible pattern matching** with regex, literal, and custom matchers
11//! - **SSH backend** for remote automation (feature: `ssh`)
12//! - **Mock backend** for testing (feature: `mock`)
13//! - **Screen buffer** with ANSI parsing (feature: `screen`)
14//! - **PII redaction** for sensitive data handling (feature: `pii-redaction`)
15//!
16//! # Example
17//!
18//! ```ignore
19//! use rust_expect::prelude::*;
20//!
21//! #[tokio::main]
22//! async fn main() -> Result<(), ExpectError> {
23//!     let mut session = Session::spawn("/bin/bash", &[]).await?;
24//!     session.expect("$").await?;
25//!     session.send_line("echo hello").await?;
26//!     session.expect("hello").await?;
27//!     Ok(())
28//! }
29//! ```
30
31// Re-export macros
32pub use rust_expect_macros::{dialog, patterns, regex, timeout};
33
34// Core types (Phase 4)
35pub mod config;
36pub mod encoding;
37pub mod error;
38pub mod prelude;
39pub mod types;
40pub mod validation;
41
42// Core modules (Phase 5)
43pub mod backend;
44pub mod expect;
45pub mod send;
46pub mod session;
47pub mod sync;
48pub mod util;
49
50// Feature modules (Phase 6)
51pub mod auto_config;
52pub mod dialog;
53pub mod health;
54pub mod interact;
55pub mod metrics;
56pub mod multi;
57pub mod transcript;
58
59/// Mock backend for testing.
60#[cfg(feature = "mock")]
61pub mod mock;
62
63/// Screen buffer with ANSI parsing.
64#[cfg(feature = "screen")]
65pub mod screen;
66
67/// PII detection and redaction.
68#[cfg(feature = "pii-redaction")]
69pub mod pii;
70
71// Re-export commonly used items from Phase 4
72// Re-export commonly used items from Phase 6
73pub use auto_config::{LocaleInfo, ShellType, detect_shell};
74// Re-export commonly used items from Phase 5
75pub use backend::{BackendType, PtyConfig, PtySpawner};
76pub use config::{
77    BufferConfig, EncodingConfig, HumanTypingConfig, InteractConfig, LineEnding, LogFormat,
78    LoggingConfig, SessionConfig, TimeoutConfig,
79};
80pub use dialog::{Dialog, DialogBuilder, DialogStep};
81pub use encoding::{
82    DetectedEncoding, EncodedText, LineEndingStyle, decode_utf8_lossy, detect_encoding_from_env,
83    detect_line_ending, normalize_line_endings, strip_ansi,
84};
85pub use error::{ExpectError, Result, SpawnError};
86pub use expect::{
87    CacheStats, CompiledRegex, GLOBAL_CACHE, Matcher, Pattern, PatternManager, PatternSet,
88    RegexCache, RingBuffer, get_regex,
89};
90pub use health::{HealthChecker, HealthStatus};
91pub use interact::{
92    InteractAction, InteractBuilder, InteractContext, InteractEndReason, InteractResult,
93    InteractionMode, ResizeContext, ResizeHook, TerminalMode, TerminalState,
94};
95pub use metrics::{Counter, Gauge, Histogram, MetricsRegistry, SessionMetrics};
96// Conditional re-exports
97#[cfg(feature = "mock")]
98pub use mock::{MockBuilder, MockSession, MockTransport, Scenario};
99pub use multi::{
100    GroupBuilder, GroupManager, GroupResult, MultiSessionManager, PatternSelector, ReadyType,
101    SelectResult, SendResult, SessionGroup,
102};
103#[cfg(feature = "pii-redaction")]
104pub use pii::{PiiDetector, PiiRedactor, PiiType};
105#[cfg(feature = "screen")]
106pub use screen::{Attributes, Cell, ScreenBuffer};
107pub use send::{AnsiSend, BasicSend, HumanTyper, Sender};
108pub use session::{QuickSession, Session, SessionBuilder};
109pub use sync::{SyncSession, block_on};
110pub use transcript::{Player, Recorder, Transcript, TranscriptEvent};
111pub use types::{
112    ControlChar, Dimensions, ExpectResult, Match, ProcessExitStatus, SessionId, SessionState,
113};
114pub use util::{Backpressure, Deadline, TimeoutExt};
115
116// Test utilities (Phase 7)
117#[cfg(any(test, feature = "test-utils"))]
118pub mod test_utils;
119
120#[cfg(any(test, feature = "test-utils"))]
121pub use test_utils::{
122    ExpectTestBuilder, FakePty, FakePtyPair, Fixtures, OutputAssertions, RecordedInteraction,
123    SessionTestBuilder, TestFixture, TestSession, TestSessionBuilder, assert_output_contains,
124    assert_output_matches,
125};