Expand description
Interactive session with pattern hooks.
This module provides the interactive session functionality with pattern-based callbacks. When patterns match in the output, registered callbacks are triggered.
§Example
ⓘ
use rust_expect::Session;
#[tokio::main]
async fn main() -> Result<(), rust_expect::ExpectError> {
let mut session = Session::spawn("/bin/bash", &[]).await?;
session.interact()
.on_output("password:", |ctx| {
println!("Password prompt detected!");
ctx.send("secret\n")
})
.on_output("logout", |_| {
InteractAction::Stop
})
.start()
.await?;
Ok(())
}Structs§
- Interact
Builder - Builder for configuring interactive sessions.
- Interact
Context - Context passed to pattern hook callbacks.
- Interact
Result - Result of an interactive session.
- Resize
Context - Context passed to resize hook callbacks.
Enums§
- Interact
Action - Action to take after a pattern match in interactive mode.
- Interact
EndReason - Reason the interaction ended.
Type Aliases§
- Pattern
Hook - Type alias for pattern hook callbacks.
- Resize
Hook - Type alias for resize hook callbacks.