Module session

Module session 

Source
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§

InteractBuilder
Builder for configuring interactive sessions.
InteractContext
Context passed to pattern hook callbacks.
InteractResult
Result of an interactive session.
ResizeContext
Context passed to resize hook callbacks.

Enums§

InteractAction
Action to take after a pattern match in interactive mode.
InteractEndReason
Reason the interaction ended.

Type Aliases§

PatternHook
Type alias for pattern hook callbacks.
ResizeHook
Type alias for resize hook callbacks.