1use rmux_proto::{
2 BreakPaneRequest, ClockModeRequest, CopyModeRequest, DisplayPanesRequest, JoinPaneRequest,
3 KillPaneRequest, LastPaneRequest, MovePaneRequest, PaneTarget, PipePaneRequest, Request,
4 ResizePaneAdjustment, ResizePaneRequest, RespawnPaneRequest, Response,
5 SelectPaneAdjacentRequest, SelectPaneDirection, SelectPaneMarkRequest, SelectPaneRequest,
6 SendKeysExtRequest, SendKeysRequest, SendPrefixRequest, SessionName, SwapPaneDirection,
7 SwapPaneRequest, WindowTarget,
8};
9
10use crate::{connection::Connection, ClientError};
11
12impl Connection {
13 pub fn swap_pane(
15 &mut self,
16 source: PaneTarget,
17 target: PaneTarget,
18 detached: bool,
19 preserve_zoom: bool,
20 ) -> Result<Response, ClientError> {
21 self.roundtrip(&Request::SwapPane(SwapPaneRequest {
22 source,
23 target,
24 direction: None,
25 detached,
26 preserve_zoom,
27 }))
28 }
29
30 pub fn swap_pane_with_next(
32 &mut self,
33 target: PaneTarget,
34 detached: bool,
35 preserve_zoom: bool,
36 ) -> Result<Response, ClientError> {
37 self.roundtrip(&Request::SwapPane(SwapPaneRequest {
38 source: target.clone(),
39 target,
40 direction: Some(SwapPaneDirection::Down),
41 detached,
42 preserve_zoom,
43 }))
44 }
45
46 pub fn swap_pane_with_previous(
48 &mut self,
49 target: PaneTarget,
50 detached: bool,
51 preserve_zoom: bool,
52 ) -> Result<Response, ClientError> {
53 self.roundtrip(&Request::SwapPane(SwapPaneRequest {
54 source: target.clone(),
55 target,
56 direction: Some(SwapPaneDirection::Up),
57 detached,
58 preserve_zoom,
59 }))
60 }
61
62 pub fn last_pane(&mut self, target: WindowTarget) -> Result<Response, ClientError> {
64 self.roundtrip(&Request::LastPane(LastPaneRequest { target }))
65 }
66
67 pub fn join_pane(&mut self, request: JoinPaneRequest) -> Result<Response, ClientError> {
69 self.roundtrip(&Request::JoinPane(request))
70 }
71
72 pub fn move_pane(&mut self, request: MovePaneRequest) -> Result<Response, ClientError> {
74 self.roundtrip(&Request::MovePane(request))
75 }
76
77 pub fn break_pane(&mut self, request: BreakPaneRequest) -> Result<Response, ClientError> {
79 self.roundtrip(&Request::BreakPane(request))
80 }
81
82 pub fn resize_pane(
84 &mut self,
85 target: PaneTarget,
86 adjustment: ResizePaneAdjustment,
87 ) -> Result<Response, ClientError> {
88 self.roundtrip(&Request::ResizePane(ResizePaneRequest {
89 target,
90 adjustment,
91 }))
92 }
93
94 pub fn display_panes(
96 &mut self,
97 target: SessionName,
98 duration_ms: Option<u64>,
99 non_blocking: bool,
100 no_command: bool,
101 template: Option<String>,
102 ) -> Result<Response, ClientError> {
103 let request = Request::DisplayPanes(DisplayPanesRequest {
104 target,
105 duration_ms,
106 non_blocking,
107 no_command,
108 template,
109 });
110 if non_blocking {
111 self.roundtrip(&request)
112 } else {
113 self.roundtrip_without_read_timeout(&request)
114 }
115 }
116
117 pub fn pipe_pane(
119 &mut self,
120 target: PaneTarget,
121 stdin: bool,
122 stdout: bool,
123 once: bool,
124 command: Option<String>,
125 ) -> Result<Response, ClientError> {
126 self.roundtrip(&Request::PipePane(PipePaneRequest {
127 target,
128 stdin,
129 stdout,
130 once,
131 command,
132 }))
133 }
134
135 pub fn respawn_pane(&mut self, request: RespawnPaneRequest) -> Result<Response, ClientError> {
137 self.roundtrip(&Request::RespawnPane(request))
138 }
139
140 pub fn select_pane(&mut self, target: PaneTarget) -> Result<Response, ClientError> {
142 self.select_pane_with_title(target, None)
143 }
144
145 pub fn select_pane_with_title(
147 &mut self,
148 target: PaneTarget,
149 title: Option<String>,
150 ) -> Result<Response, ClientError> {
151 self.roundtrip(&Request::SelectPane(SelectPaneRequest { target, title }))
152 }
153
154 pub fn select_pane_adjacent(
156 &mut self,
157 target: PaneTarget,
158 direction: SelectPaneDirection,
159 ) -> Result<Response, ClientError> {
160 self.roundtrip(&Request::SelectPaneAdjacent(SelectPaneAdjacentRequest {
161 target,
162 direction,
163 }))
164 }
165
166 pub fn select_pane_mark(
168 &mut self,
169 target: PaneTarget,
170 clear: bool,
171 ) -> Result<Response, ClientError> {
172 self.select_pane_mark_with_title(target, clear, None)
173 }
174
175 pub fn select_pane_mark_with_title(
177 &mut self,
178 target: PaneTarget,
179 clear: bool,
180 title: Option<String>,
181 ) -> Result<Response, ClientError> {
182 self.roundtrip(&Request::SelectPaneMark(SelectPaneMarkRequest {
183 target,
184 clear,
185 title,
186 }))
187 }
188
189 pub fn kill_pane(&mut self, target: PaneTarget) -> Result<Response, ClientError> {
191 self.kill_pane_with_options(target, false)
192 }
193
194 pub fn kill_pane_with_options(
196 &mut self,
197 target: PaneTarget,
198 kill_all_except: bool,
199 ) -> Result<Response, ClientError> {
200 self.roundtrip(&Request::KillPane(KillPaneRequest {
201 target,
202 kill_all_except,
203 }))
204 }
205
206 pub fn send_keys(
208 &mut self,
209 target: PaneTarget,
210 keys: Vec<String>,
211 ) -> Result<Response, ClientError> {
212 self.roundtrip(&Request::SendKeys(SendKeysRequest { target, keys }))
213 }
214
215 pub fn send_keys_extended(
217 &mut self,
218 request: SendKeysExtRequest,
219 ) -> Result<Response, ClientError> {
220 self.roundtrip(&Request::SendKeysExt(request))
221 }
222
223 pub fn send_prefix(
225 &mut self,
226 target: Option<PaneTarget>,
227 secondary: bool,
228 ) -> Result<Response, ClientError> {
229 self.roundtrip(&Request::SendPrefix(SendPrefixRequest {
230 target,
231 secondary,
232 }))
233 }
234
235 pub fn copy_mode(&mut self, request: CopyModeRequest) -> Result<Response, ClientError> {
237 self.roundtrip(&Request::CopyMode(request))
238 }
239
240 pub fn clock_mode(&mut self, target: Option<PaneTarget>) -> Result<Response, ClientError> {
242 self.roundtrip(&Request::ClockMode(ClockModeRequest { target }))
243 }
244}