pub struct Connection<S> { /* private fields */ }Expand description
A WebSocket connection to iTerm2.
Manages request-response matching and notification dispatch via a background task. Clone-friendly — all clones share the same underlying connection.
Implementations§
Source§impl Connection<MaybeTlsStream<TcpStream>>
impl Connection<MaybeTlsStream<TcpStream>>
Sourcepub async fn connect_tcp(app_name: &str) -> Result<Self>
pub async fn connect_tcp(app_name: &str) -> Result<Self>
Connect to iTerm2 over legacy TCP at ws://localhost:1912.
Modern iTerm2 no longer serves TCP — prefer Connection::connect instead.
Sourcepub async fn connect_tcp_with_credentials(
app_name: &str,
credentials: &Credentials,
) -> Result<Self>
pub async fn connect_tcp_with_credentials( app_name: &str, credentials: &Credentials, ) -> Result<Self>
Connect to iTerm2 over legacy TCP with pre-resolved credentials.
Source§impl Connection<UnixStream>
impl Connection<UnixStream>
Sourcepub async fn connect(app_name: &str) -> Result<Self>
pub async fn connect(app_name: &str) -> Result<Self>
Connect to iTerm2, resolving credentials automatically.
Connects via Unix domain socket at
~/Library/Application Support/iTerm2/private/socket, which is the
only transport modern iTerm2 serves. For legacy TCP connections, use
Connection::connect_tcp.
Sourcepub async fn connect_unix(app_name: &str) -> Result<Self>
pub async fn connect_unix(app_name: &str) -> Result<Self>
Connect to iTerm2 over Unix socket, resolving credentials automatically.
Sourcepub async fn connect_with_runner(
app_name: &str,
runner: &dyn AppleScriptRunner,
) -> Result<Self>
pub async fn connect_with_runner( app_name: &str, runner: &dyn AppleScriptRunner, ) -> Result<Self>
Connect to iTerm2 using a custom AppleScriptRunner for credential resolution.
Sourcepub async fn connect_with_credentials(
app_name: &str,
credentials: &Credentials,
) -> Result<Self>
pub async fn connect_with_credentials( app_name: &str, credentials: &Credentials, ) -> Result<Self>
Connect to iTerm2 over Unix socket with pre-resolved credentials.
Source§impl<S: AsyncRead + AsyncWrite + Unpin + Send + 'static> Connection<S>
impl<S: AsyncRead + AsyncWrite + Unpin + Send + 'static> Connection<S>
Sourcepub fn from_split(sink: WsSink<S>, source: WsSource<S>) -> Self
pub fn from_split(sink: WsSink<S>, source: WsSource<S>) -> Self
Create a connection from pre-established WebSocket sink and source streams.
This is useful for testing with mock servers or custom transports.
Sourcepub async fn call(
&self,
request: ClientOriginatedMessage,
) -> Result<ServerOriginatedMessage>
pub async fn call( &self, request: ClientOriginatedMessage, ) -> Result<ServerOriginatedMessage>
Send a request and wait for the matching response (10-second default timeout).
Sourcepub async fn call_with_timeout(
&self,
request: ClientOriginatedMessage,
timeout: Duration,
) -> Result<ServerOriginatedMessage>
pub async fn call_with_timeout( &self, request: ClientOriginatedMessage, timeout: Duration, ) -> Result<ServerOriginatedMessage>
Send a request and wait for the matching response with a custom timeout.
Sourcepub fn subscribe_notifications(&self) -> Receiver<Notification>
pub fn subscribe_notifications(&self) -> Receiver<Notification>
Subscribe to spontaneous notifications from iTerm2.
Returns a broadcast receiver. Multiple subscribers can be active concurrently.
Use the helpers in crate::notification for typed filtering.