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: StringThe unique session identifier.
title: Option<String>The session’s title, if available.
Implementations§
Source§impl<S: AsyncRead + AsyncWrite + Unpin + Send + 'static> Session<S>
impl<S: AsyncRead + AsyncWrite + Unpin + Send + 'static> Session<S>
Sourcepub fn new(
id: String,
title: Option<String>,
conn: Arc<Connection<S>>,
) -> Result<Self>
pub fn new( id: String, title: Option<String>, conn: Arc<Connection<S>>, ) -> Result<Self>
Create a session handle. Validates the session ID.
Sourcepub async fn send_text(&self, text: &str) -> Result<()>
pub async fn send_text(&self, text: &str) -> Result<()>
Send text to the session as if typed on the keyboard.
Sourcepub async fn get_screen_contents(&self) -> Result<Vec<String>>
pub async fn get_screen_contents(&self) -> Result<Vec<String>>
Get the current visible screen contents as lines of text.
Sourcepub async fn get_buffer_lines(&self, trailing_lines: i32) -> Result<Vec<String>>
pub async fn get_buffer_lines(&self, trailing_lines: i32) -> Result<Vec<String>>
Get the last N lines from the scrollback buffer.
Sourcepub async fn split(
&self,
direction: SplitDirection,
before: bool,
profile_name: Option<&str>,
) -> Result<Vec<String>>
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).
Sourcepub async fn get_variable(&self, name: &str) -> Result<Option<String>>
pub async fn get_variable(&self, name: &str) -> Result<Option<String>>
Get a session variable by name. Returns JSON-encoded value.
Sourcepub async fn set_variable(&self, name: &str, json_value: &str) -> Result<()>
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.
Sourcepub async fn get_profile_property(
&self,
keys: Vec<String>,
) -> Result<Vec<ProfileProperty>>
pub async fn get_profile_property( &self, keys: Vec<String>, ) -> Result<Vec<ProfileProperty>>
Get profile properties for this session.
Sourcepub async fn set_profile_property(
&self,
key: &str,
json_value: &str,
) -> Result<()>
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.
Sourcepub async fn inject(&self, data: Vec<u8>) -> Result<()>
pub async fn inject(&self, data: Vec<u8>) -> Result<()>
Inject bytes into the terminal as if produced by the running program.
Sourcepub async fn restart(&self, only_if_exited: bool) -> Result<()>
pub async fn restart(&self, only_if_exited: bool) -> Result<()>
Restart the session’s shell process.
Sourcepub async fn close(&self, force: bool) -> Result<()>
pub async fn close(&self, force: bool) -> Result<()>
Close this session. If force is true, skip the confirmation prompt.
Sourcepub async fn activate(&self) -> Result<()>
pub async fn activate(&self) -> Result<()>
Activate this session (bring its window to front and select it).
Sourcepub async fn get_prompt(&self) -> Result<GetPromptResponse>
pub async fn get_prompt(&self) -> Result<GetPromptResponse>
Get metadata about the current shell prompt (command, working directory, state).
Sourcepub fn connection(&self) -> &Connection<S>
pub fn connection(&self) -> &Connection<S>
Get a reference to the underlying connection.