pub struct InteractBuilder<'a, T>{ /* private fields */ }Expand description
Builder for configuring interactive sessions.
Implementations§
Source§impl<'a, T> InteractBuilder<'a, T>
impl<'a, T> InteractBuilder<'a, T>
Sourcepub fn on_input<F>(self, pattern: impl Into<Pattern>, callback: F) -> Self
pub fn on_input<F>(self, pattern: impl Into<Pattern>, callback: F) -> Self
Register a pattern hook for input.
When the input matches the pattern, the callback is invoked.
Sourcepub fn on_resize<F>(self, callback: F) -> Self
pub fn on_resize<F>(self, callback: F) -> Self
Register a hook for terminal resize events.
On Unix systems, this is triggered by SIGWINCH. The callback receives the new terminal size and can optionally return an action.
§Example
session.interact()
.on_resize(|ctx| {
println!("Terminal resized to {}x{}", ctx.size.cols, ctx.size.rows);
InteractAction::Continue
})
.start()
.await?;§Platform Support
- Unix: Resize events are detected via SIGWINCH signal handling.
- Windows: Resize detection is not currently supported; the callback will not be invoked.
Sourcepub const fn with_mode(self, mode: InteractionMode) -> Self
pub const fn with_mode(self, mode: InteractionMode) -> Self
Set the interaction mode.
Sourcepub fn with_escape(self, escape: impl Into<Vec<u8>>) -> Self
pub fn with_escape(self, escape: impl Into<Vec<u8>>) -> Self
Set the escape sequence to exit interact mode.
Default is Ctrl+] (0x1d).
Sourcepub fn no_escape(self) -> Self
pub fn no_escape(self) -> Self
Disable the escape sequence (interact runs until pattern stops it).
Sourcepub const fn with_timeout(self, timeout: Duration) -> Self
pub const fn with_timeout(self, timeout: Duration) -> Self
Set a timeout for the interaction.
Sourcepub const fn with_buffer_size(self, size: usize) -> Self
pub const fn with_buffer_size(self, size: usize) -> Self
Set the output buffer size.
Sourcepub fn with_input_hook<F>(self, hook: F) -> Self
pub fn with_input_hook<F>(self, hook: F) -> Self
Add a byte-level input hook.
Sourcepub fn with_output_hook<F>(self, hook: F) -> Self
pub fn with_output_hook<F>(self, hook: F) -> Self
Add a byte-level output hook.
Sourcepub async fn start(self) -> Result<InteractResult>
pub async fn start(self) -> Result<InteractResult>
Start the interactive session.
This runs the interaction loop, reading from stdin and the session, checking patterns, and invoking callbacks when matches occur.
The interaction continues until:
- A pattern callback returns
InteractAction::Stop - The escape sequence is detected
- A timeout occurs (if configured)
- EOF is reached on the session
§Errors
Returns an error if I/O fails or a pattern callback returns an error.