Skip to main content

Session

Struct Session 

Source
pub struct Session<S> {
    pub id: String,
    pub title: Option<String>,
    /* private fields */
}
Expand description

A handle to an iTerm2 session (a single terminal pane).

Provides methods to send text, read the terminal buffer, split panes, manage variables/properties, and more.

Fields§

§id: String

The unique session identifier.

§title: Option<String>

The session’s title, if available.

Implementations§

Source§

impl<S: AsyncRead + AsyncWrite + Unpin + Send + 'static> Session<S>

Source

pub fn new( id: String, title: Option<String>, conn: Arc<Connection<S>>, ) -> Result<Self>

Create a session handle. Validates the session ID.

Source

pub async fn send_text(&self, text: &str) -> Result<()>

Send text to the session as if typed on the keyboard.

Source

pub async fn get_screen_contents(&self) -> Result<Vec<String>>

Get the current visible screen contents as lines of text.

Source

pub async fn get_buffer_lines(&self, trailing_lines: i32) -> Result<Vec<String>>

Get the last N lines from the scrollback buffer.

Source

pub async fn split( &self, direction: SplitDirection, before: bool, profile_name: Option<&str>, ) -> Result<Vec<String>>

Split this session’s pane. Returns the new session ID(s).

Source

pub async fn get_variable(&self, name: &str) -> Result<Option<String>>

Get a session variable by name. Returns JSON-encoded value.

Source

pub async fn set_variable(&self, name: &str, json_value: &str) -> Result<()>

Set a session variable. Name must start with user.. Value must be valid JSON.

Source

pub async fn get_profile_property( &self, keys: Vec<String>, ) -> Result<Vec<ProfileProperty>>

Get profile properties for this session.

Source

pub async fn set_profile_property( &self, key: &str, json_value: &str, ) -> Result<()>

Set a profile property on this session’s copy of the profile. Value must be valid JSON.

Source

pub async fn inject(&self, data: Vec<u8>) -> Result<()>

Inject bytes into the terminal as if produced by the running program.

Source

pub async fn restart(&self, only_if_exited: bool) -> Result<()>

Restart the session’s shell process.

Source

pub async fn close(&self, force: bool) -> Result<()>

Close this session. If force is true, skip the confirmation prompt.

Source

pub async fn activate(&self) -> Result<()>

Activate this session (bring its window to front and select it).

Source

pub async fn get_prompt(&self) -> Result<GetPromptResponse>

Get metadata about the current shell prompt (command, working directory, state).

Source

pub fn connection(&self) -> &Connection<S>

Get a reference to the underlying connection.

Auto Trait Implementations§

§

impl<S> Freeze for Session<S>

§

impl<S> !RefUnwindSafe for Session<S>

§

impl<S> Send for Session<S>
where S: Send,

§

impl<S> Sync for Session<S>
where S: Send,

§

impl<S> Unpin for Session<S>

§

impl<S> UnsafeUnpin for Session<S>

§

impl<S> !UnwindSafe for Session<S>

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> Same for T

Source§

type Output = T

Should always be Self
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