SyncSession

Struct SyncSession 

Source
pub struct SyncSession { /* private fields */ }
Expand description

A synchronous session wrapper.

This wraps an async session and provides blocking methods for use in synchronous contexts.

Implementations§

Source§

impl SyncSession

Source

pub fn spawn(command: &str, args: &[&str]) -> Result<Self>

Spawn a command and create a session.

§Errors

Returns an error if spawning fails.

Source

pub fn spawn_with_config( command: &str, args: &[&str], config: SessionConfig, ) -> Result<Self>

Spawn with custom configuration.

§Errors

Returns an error if spawning fails.

Source

pub const fn config(&self) -> &SessionConfig

Get the session configuration.

Source

pub const fn is_active(&self) -> bool

Check if the session is active.

Source

pub fn pid(&self) -> u32

Get the child process ID.

Source

pub fn send(&mut self, data: &[u8]) -> Result<()>

Send bytes to the session.

§Errors

Returns an error if the write fails.

Source

pub fn send_str(&mut self, s: &str) -> Result<()>

Send a string to the session.

§Errors

Returns an error if the write fails.

Source

pub fn send_line(&mut self, line: &str) -> Result<()>

Send a line to the session.

§Errors

Returns an error if the write fails.

Source

pub fn send_control(&mut self, ctrl: ControlChar) -> Result<()>

Send a control character.

§Errors

Returns an error if the write fails.

Source

pub fn expect(&mut self, pattern: impl Into<Pattern>) -> Result<Match>

Expect a pattern in the output.

§Errors

Returns an error on timeout or EOF.

Source

pub fn expect_timeout( &mut self, pattern: impl Into<Pattern>, timeout: Duration, ) -> Result<Match>

Expect a pattern with a specific timeout.

§Errors

Returns an error on timeout or EOF.

Source

pub fn buffer(&mut self) -> String

Get the current buffer contents.

Source

pub fn clear_buffer(&mut self)

Clear the buffer.

Source

pub fn resize(&mut self, cols: u16, rows: u16) -> Result<()>

Resize the terminal.

§Errors

Returns an error if the resize fails.

Source

pub fn signal(&self, signal: i32) -> Result<()>

Send a signal to the child process.

§Errors

Returns an error if sending the signal fails.

Source

pub fn kill(&self) -> Result<()>

Kill the child process.

§Errors

Returns an error if killing fails.

Source

pub fn block_on<F, T>(&self, future: F) -> T
where F: Future<Output = T>,

Run an async operation synchronously.

Trait Implementations§

Source§

impl Debug for SyncSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V