tmux_interface/commands/windows_and_panes/
resize_pane.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type ResizeP<'a> = ResizePane<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
41pub struct ResizePane<'a> {
42 #[cfg(feature = "tmux_0_9")]
44 pub down: bool,
45
46 #[cfg(feature = "tmux_1_8")]
48 pub left: bool,
49
50 #[cfg(feature = "tmux_2_1")]
52 pub mouse: bool,
53
54 #[cfg(feature = "tmux_1_8")]
56 pub right: bool,
57
58 #[cfg(feature = "tmux_3_2")]
60 pub trim: bool,
61
62 #[cfg(feature = "tmux_0_9")]
64 pub up: bool,
65
66 #[cfg(feature = "tmux_1_8")]
68 pub zoom: bool,
69
70 #[cfg(feature = "tmux_0_9")]
72 pub target_pane: Option<Cow<'a, str>>,
73
74 #[cfg(feature = "tmux_1_8")]
76 pub width: Option<usize>,
77
78 #[cfg(feature = "tmux_1_8")]
80 pub height: Option<usize>,
81
82 #[cfg(feature = "tmux_0_9")]
84 pub adjustment: Option<Cow<'a, str>>,
85}
86
87impl<'a> ResizePane<'a> {
88 pub fn new() -> Self {
89 Default::default()
90 }
91
92 #[cfg(feature = "tmux_0_9")]
94 pub fn down(mut self) -> Self {
95 self.down = true;
96 self
97 }
98
99 #[cfg(feature = "tmux_1_8")]
101 pub fn left(mut self) -> Self {
102 self.left = true;
103 self
104 }
105
106 #[cfg(feature = "tmux_2_1")]
108 pub fn mouse(mut self) -> Self {
109 self.mouse = true;
110 self
111 }
112
113 #[cfg(feature = "tmux_1_8")]
115 pub fn right(mut self) -> Self {
116 self.right = true;
117 self
118 }
119
120 #[cfg(feature = "tmux_3_2")]
122 pub fn trim(mut self) -> Self {
123 self.trim = true;
124 self
125 }
126
127 #[cfg(feature = "tmux_0_9")]
129 pub fn up(mut self) -> Self {
130 self.up = true;
131 self
132 }
133
134 #[cfg(feature = "tmux_1_8")]
136 pub fn zoom(mut self) -> Self {
137 self.zoom = true;
138 self
139 }
140
141 #[cfg(feature = "tmux_0_9")]
143 pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
144 self.target_pane = Some(target_pane.into());
145 self
146 }
147
148 #[cfg(feature = "tmux_1_8")]
150 pub fn width(mut self, width: usize) -> Self {
151 self.width = Some(width);
152 self
153 }
154
155 #[cfg(feature = "tmux_1_8")]
157 pub fn height(mut self, height: usize) -> Self {
158 self.height = Some(height);
159 self
160 }
161
162 #[cfg(feature = "tmux_0_9")]
164 pub fn adjustment<S: Into<Cow<'a, str>>>(mut self, adjustment: S) -> Self {
165 self.adjustment = Some(adjustment.into());
166 self
167 }
168
169 pub fn build(self) -> TmuxCommand<'a> {
170 let mut cmd = TmuxCommand::new();
171
172 cmd.name(RESIZE_PANE);
173
174 #[cfg(feature = "tmux_0_9")]
176 if self.down {
177 cmd.push_flag(D_UPPERCASE_KEY);
178 }
179
180 #[cfg(feature = "tmux_1_8")]
182 if self.left {
183 cmd.push_flag(L_UPPERCASE_KEY);
184 }
185
186 #[cfg(feature = "tmux_2_1")]
188 if self.mouse {
189 cmd.push_flag(M_UPPERCASE_KEY);
190 }
191
192 #[cfg(feature = "tmux_1_8")]
194 if self.right {
195 cmd.push_flag(R_UPPERCASE_KEY);
196 }
197
198 #[cfg(feature = "tmux_3_2")]
200 if self.trim {
201 cmd.push_flag(T_UPPERCASE_KEY);
202 }
203
204 #[cfg(feature = "tmux_0_9")]
206 if self.up {
207 cmd.push_flag(U_UPPERCASE_KEY);
208 }
209
210 #[cfg(feature = "tmux_1_8")]
212 if self.zoom {
213 cmd.push_flag(Z_UPPERCASE_KEY);
214 }
215
216 #[cfg(feature = "tmux_0_9")]
218 if let Some(target_pane) = self.target_pane {
219 cmd.push_option(T_LOWERCASE_KEY, target_pane);
220 }
221
222 #[cfg(feature = "tmux_1_8")]
224 if let Some(width) = self.width {
225 cmd.push_option(X_LOWERCASE_KEY, width.to_string());
226 }
227
228 #[cfg(feature = "tmux_1_8")]
230 if let Some(height) = self.height {
231 cmd.push_option(Y_LOWERCASE_KEY, height.to_string());
232 }
233
234 #[cfg(feature = "tmux_0_9")]
236 if let Some(adjustment) = self.adjustment {
237 cmd.push_param(adjustment);
238 }
239
240 cmd
241 }
242}