use rmux_proto::{
BreakPaneRequest, CancelSdkWaitRequest, ClockModeRequest, CopyModeRequest, DisplayPanesRequest,
JoinPaneRequest, KillPaneRequest, LastPaneRequest, MovePaneRequest, PaneBroadcastInputRequest,
PaneInputRequest, PaneOutputCursorRequest, PaneOutputSubscriptionId,
PaneOutputSubscriptionStart, PaneSnapshotRefRequest, PaneTarget, PaneTargetRef,
PipePaneRequest, Request, ResizePaneAdjustment, ResizePaneRequest,
ResizePaneTargetActionRequest, RespawnPaneRequest, Response, SdkWaitForOutputRefRequest,
SdkWaitId, SdkWaitOwnerId, SelectPaneAdjacentRequest, SelectPaneDirection,
SelectPaneMarkRequest, SelectPaneRequest, SendKeysExt2Request, SendKeysExtRequest,
SendKeysRequest, SendPrefixRequest, SessionName, SubscribePaneOutputRefRequest,
SwapPaneDirection, SwapPaneRequest, UnsubscribePaneOutputRequest, WindowTarget,
CAPABILITY_SDK_PANE_BROADCAST, CAPABILITY_SDK_PANE_BY_ID, CAPABILITY_SDK_WAITS,
CAPABILITY_TARGET_CLIENT_COMMANDS,
};
use crate::{connection::Connection, ClientError};
impl Connection {
pub fn swap_pane(
&mut self,
source: PaneTarget,
target: PaneTarget,
detached: bool,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SwapPane(SwapPaneRequest {
source,
target,
direction: None,
detached,
preserve_zoom,
}))
}
pub fn swap_pane_with_next(
&mut self,
target: PaneTarget,
detached: bool,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SwapPane(SwapPaneRequest {
source: target.clone(),
target,
direction: Some(SwapPaneDirection::Down),
detached,
preserve_zoom,
}))
}
pub fn swap_pane_with_previous(
&mut self,
target: PaneTarget,
detached: bool,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SwapPane(SwapPaneRequest {
source: target.clone(),
target,
direction: Some(SwapPaneDirection::Up),
detached,
preserve_zoom,
}))
}
pub fn last_pane(&mut self, target: WindowTarget) -> Result<Response, ClientError> {
self.last_pane_with_zoom(target, false)
}
pub fn last_pane_with_zoom(
&mut self,
target: WindowTarget,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.last_pane_with_options(target, preserve_zoom, None)
}
pub fn last_pane_with_options(
&mut self,
target: WindowTarget,
preserve_zoom: bool,
input_disabled: Option<bool>,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::LastPane(LastPaneRequest {
target,
preserve_zoom,
input_disabled,
}))
}
pub fn join_pane(&mut self, request: JoinPaneRequest) -> Result<Response, ClientError> {
self.roundtrip(&Request::JoinPane(request))
}
pub fn move_pane(&mut self, request: MovePaneRequest) -> Result<Response, ClientError> {
self.roundtrip(&Request::MovePane(request))
}
pub fn break_pane(&mut self, request: BreakPaneRequest) -> Result<Response, ClientError> {
self.roundtrip(&Request::BreakPane(Box::new(request)))
}
pub fn resize_pane(
&mut self,
target: PaneTarget,
adjustment: ResizePaneAdjustment,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::ResizePane(ResizePaneRequest {
target,
adjustment,
}))
}
pub fn resize_pane_target_action(
&mut self,
request: ResizePaneTargetActionRequest,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::ResizePaneTargetAction(request))
}
pub fn display_panes(
&mut self,
target: SessionName,
duration_ms: Option<u64>,
non_blocking: bool,
no_command: bool,
template: Option<String>,
) -> Result<Response, ClientError> {
self.display_panes_target_client(
target,
duration_ms,
non_blocking,
no_command,
template,
None,
)
}
#[allow(clippy::too_many_arguments)]
pub fn display_panes_target_client(
&mut self,
target: SessionName,
duration_ms: Option<u64>,
non_blocking: bool,
no_command: bool,
template: Option<String>,
target_client: Option<String>,
) -> Result<Response, ClientError> {
let request = Request::DisplayPanes(Box::new(DisplayPanesRequest {
target,
duration_ms,
non_blocking,
no_command,
template,
target_client,
}));
if non_blocking {
self.roundtrip(&request)
} else {
self.roundtrip_without_read_timeout(&request)
}
}
pub fn pipe_pane(
&mut self,
target: PaneTarget,
stdin: bool,
stdout: bool,
once: bool,
command: Option<String>,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::PipePane(PipePaneRequest {
target,
stdin,
stdout,
once,
command,
}))
}
pub fn respawn_pane(&mut self, request: RespawnPaneRequest) -> Result<Response, ClientError> {
self.roundtrip(&Request::RespawnPane(Box::new(request)))
}
pub fn select_pane(&mut self, target: PaneTarget) -> Result<Response, ClientError> {
self.select_pane_with_title(target, None)
}
pub fn select_pane_with_title(
&mut self,
target: PaneTarget,
title: Option<String>,
) -> Result<Response, ClientError> {
self.select_pane_with_title_and_zoom(target, title, false)
}
pub fn select_pane_with_title_and_zoom(
&mut self,
target: PaneTarget,
title: Option<String>,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.select_pane_with_options(target, title, None, None, preserve_zoom)
}
pub fn select_pane_with_options(
&mut self,
target: PaneTarget,
title: Option<String>,
style: Option<String>,
input_disabled: Option<bool>,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SelectPane(Box::new(SelectPaneRequest {
target,
title,
input_disabled,
preserve_zoom,
style,
})))
}
pub fn select_pane_input(
&mut self,
target: PaneTarget,
disabled: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SelectPane(Box::new(SelectPaneRequest {
target,
title: None,
style: None,
input_disabled: Some(disabled),
preserve_zoom: false,
})))
}
pub fn select_pane_adjacent(
&mut self,
target: PaneTarget,
direction: SelectPaneDirection,
) -> Result<Response, ClientError> {
self.select_pane_adjacent_with_zoom(target, direction, false)
}
pub fn select_pane_adjacent_with_zoom(
&mut self,
target: PaneTarget,
direction: SelectPaneDirection,
preserve_zoom: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SelectPaneAdjacent(SelectPaneAdjacentRequest {
target,
direction,
preserve_zoom,
}))
}
pub fn select_pane_mark(
&mut self,
target: PaneTarget,
clear: bool,
) -> Result<Response, ClientError> {
self.select_pane_mark_with_title(target, clear, None)
}
pub fn select_pane_mark_with_title(
&mut self,
target: PaneTarget,
clear: bool,
title: Option<String>,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SelectPaneMark(SelectPaneMarkRequest {
target,
clear,
title,
}))
}
pub fn kill_pane(&mut self, target: PaneTarget) -> Result<Response, ClientError> {
self.kill_pane_with_options(target, false)
}
pub fn kill_pane_with_options(
&mut self,
target: PaneTarget,
kill_all_except: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::KillPane(KillPaneRequest {
target,
kill_all_except,
}))
}
pub fn send_keys(
&mut self,
target: PaneTarget,
keys: Vec<String>,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SendKeys(SendKeysRequest { target, keys }))
}
pub fn send_keys_extended(
&mut self,
request: SendKeysExtRequest,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SendKeysExt(request))
}
pub fn send_keys_extended_target_client(
&mut self,
request: SendKeysExt2Request,
) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_TARGET_CLIENT_COMMANDS)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_TARGET_CLIENT_COMMANDS.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::SendKeysExt2(Box::new(request)))
}
pub fn pane_input(&mut self, request: PaneInputRequest) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_PANE_BY_ID)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_PANE_BY_ID.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::PaneInput(request))
}
pub fn pane_broadcast_input(
&mut self,
request: PaneBroadcastInputRequest,
) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_PANE_BROADCAST)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_PANE_BROADCAST.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::PaneBroadcastInput(request))
}
pub fn pane_snapshot_ref(&mut self, target: PaneTargetRef) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_PANE_BY_ID)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_PANE_BY_ID.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::PaneSnapshotRef(PaneSnapshotRefRequest { target }))
}
pub fn subscribe_pane_output_ref(
&mut self,
target: PaneTargetRef,
start: PaneOutputSubscriptionStart,
) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_PANE_BY_ID)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_PANE_BY_ID.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::SubscribePaneOutputRef(
SubscribePaneOutputRefRequest { target, start },
))
}
pub fn pane_output_cursor(
&mut self,
subscription_id: PaneOutputSubscriptionId,
max_events: Option<u16>,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::PaneOutputCursor(PaneOutputCursorRequest {
subscription_id,
max_events,
}))
}
pub fn unsubscribe_pane_output(
&mut self,
subscription_id: PaneOutputSubscriptionId,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::UnsubscribePaneOutput(
UnsubscribePaneOutputRequest { subscription_id },
))
}
pub fn sdk_wait_for_output_ref(
&mut self,
owner_id: SdkWaitOwnerId,
wait_id: SdkWaitId,
target: PaneTargetRef,
bytes: Vec<u8>,
start: PaneOutputSubscriptionStart,
) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_WAITS)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_WAITS.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip_without_read_timeout(&Request::SdkWaitForOutputRef(
SdkWaitForOutputRefRequest {
owner_id,
wait_id,
target,
bytes,
start,
},
))
}
pub fn arm_sdk_wait_for_output_ref(
&mut self,
owner_id: SdkWaitOwnerId,
wait_id: SdkWaitId,
target: PaneTargetRef,
bytes: Vec<u8>,
start: PaneOutputSubscriptionStart,
) -> Result<(), ClientError> {
if !self.supports_capability(CAPABILITY_SDK_WAITS)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_WAITS.to_owned(),
supported: Vec::new(),
},
));
}
self.write_request(&Request::SdkWaitForOutputRef(SdkWaitForOutputRefRequest {
owner_id,
wait_id,
target,
bytes,
start,
}))
}
pub fn cancel_sdk_wait(
&mut self,
owner_id: SdkWaitOwnerId,
wait_id: SdkWaitId,
) -> Result<Response, ClientError> {
if !self.supports_capability(CAPABILITY_SDK_WAITS)? {
return Err(ClientError::Protocol(
rmux_proto::RmuxError::UnsupportedCapability {
feature: CAPABILITY_SDK_WAITS.to_owned(),
supported: Vec::new(),
},
));
}
self.roundtrip(&Request::CancelSdkWait(CancelSdkWaitRequest {
owner_id,
wait_id,
}))
}
pub fn send_prefix(
&mut self,
target: Option<PaneTarget>,
secondary: bool,
) -> Result<Response, ClientError> {
self.roundtrip(&Request::SendPrefix(SendPrefixRequest {
target,
secondary,
}))
}
pub fn copy_mode(&mut self, request: CopyModeRequest) -> Result<Response, ClientError> {
self.roundtrip(&Request::CopyMode(request))
}
pub fn clock_mode(&mut self, target: Option<PaneTarget>) -> Result<Response, ClientError> {
self.roundtrip(&Request::ClockMode(ClockModeRequest { target }))
}
}