tmux_interface/commands/status_line/
display_popup.rs1use crate::commands::constants::*;
2#[cfg(feature = "tmux_3_3")]
3use crate::commands::PopupBorderLinesType;
4use crate::commands::Size;
5use crate::TmuxCommand;
6use std::borrow::Cow;
7
8pub type Popup<'a> = DisplayPopup<'a>;
9
10#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
28#[cfg(feature = "tmux_3_2")]
29pub struct DisplayPopup<'a> {
30 #[cfg(feature = "tmux_3_3")]
32 pub no_border: bool,
33
34 #[cfg(feature = "tmux_3_2")]
36 pub close: bool,
37
38 #[cfg(feature = "tmux_3_2")]
40 pub close_on_exit: bool,
41
42 #[cfg(feature = "tmux_3_2")]
44 pub close_on_success: bool,
45
46 #[cfg(feature = "tmux_3_3")]
49 pub border_lines: Option<PopupBorderLinesType>,
50
51 #[cfg(feature = "tmux_3_2")]
53 pub target_client: Option<Cow<'a, str>>,
54
55 #[cfg(feature = "tmux_3_2")]
57 pub start_directory: Option<Cow<'a, str>>,
58
59 #[cfg(feature = "tmux_3_3")]
63 pub environment: Option<(Cow<'a, str>, Cow<'a, str>)>,
64
65 #[cfg(feature = "tmux_3_2")]
67 pub height: Option<Size>,
68
69 #[cfg(feature = "tmux_3_3")]
72 pub style: Option<Cow<'a, str>>,
73
74 #[cfg(feature = "tmux_3_3")]
77 pub border_style: Option<Cow<'a, str>>,
78
79 #[cfg(feature = "tmux_3_2")]
81 pub target_pane: Option<Cow<'a, str>>,
82
83 #[cfg(feature = "tmux_3_3")]
85 pub title: Option<Cow<'a, str>>,
86
87 #[cfg(feature = "tmux_3_2")]
89 pub width: Option<Size>,
90
91 #[cfg(feature = "tmux_3_2")]
93 pub x: Option<Size>,
94
95 #[cfg(feature = "tmux_3_2")]
97 pub y: Option<Size>,
98
99 #[cfg(feature = "tmux_3_2")]
101 pub shell_command: Option<Cow<'a, str>>,
102}
103
104impl<'a> DisplayPopup<'a> {
105 pub fn new() -> Self {
106 Default::default()
107 }
108
109 #[cfg(feature = "tmux_3_3")]
111 pub fn no_border(mut self) -> Self {
112 self.no_border = true;
113 self
114 }
115
116 #[cfg(feature = "tmux_3_2")]
118 pub fn close(mut self) -> Self {
119 self.close = true;
120 self
121 }
122
123 #[cfg(feature = "tmux_3_2")]
125 pub fn close_on_exit(mut self) -> Self {
126 self.close_on_exit = true;
127 self
128 }
129
130 #[cfg(feature = "tmux_3_2")]
132 pub fn close_on_success(mut self) -> Self {
133 self.close_on_success = true;
134 self
135 }
136
137 #[cfg(feature = "tmux_3_3")]
140 pub fn border_lines(mut self, border_lines: PopupBorderLinesType) -> Self {
141 self.border_lines = Some(border_lines);
142 self
143 }
144
145 #[cfg(feature = "tmux_3_2")]
147 pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
148 self.target_client = Some(target_client.into());
149 self
150 }
151
152 #[cfg(feature = "tmux_3_2")]
154 pub fn start_directory<S: Into<Cow<'a, str>>>(mut self, start_directory: S) -> Self {
155 self.start_directory = Some(start_directory.into());
156 self
157 }
158
159 #[cfg(feature = "tmux_3_3")]
163 pub fn environment<S: Into<Cow<'a, str>>>(mut self, variable: S, value: S) -> Self {
164 self.environment = Some((variable.into(), value.into()));
165 self
166 }
167
168 #[cfg(feature = "tmux_3_2")]
170 pub fn height(mut self, height: Size) -> Self {
171 self.height = Some(height);
172 self
173 }
174
175 #[cfg(feature = "tmux_3_3")]
177 pub fn style<S: Into<Cow<'a, str>>>(mut self, style: S) -> Self {
178 self.style = Some(style.into());
179 self
180 }
181
182 #[cfg(feature = "tmux_3_3")]
184 pub fn border_style<S: Into<Cow<'a, str>>>(mut self, border_style: S) -> Self {
185 self.border_style = Some(border_style.into());
186 self
187 }
188
189 #[cfg(feature = "tmux_3_2")]
191 pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
192 self.target_pane = Some(target_pane.into());
193 self
194 }
195
196 #[cfg(feature = "tmux_3_3")]
198 pub fn title<S: Into<Cow<'a, str>>>(mut self, title: S) -> Self {
199 self.title = Some(title.into());
200 self
201 }
202
203 #[cfg(feature = "tmux_3_2")]
205 pub fn width(mut self, width: Size) -> Self {
206 self.width = Some(width);
207 self
208 }
209
210 #[cfg(feature = "tmux_3_2")]
212 pub fn x(mut self, x: Size) -> Self {
213 self.x = Some(x);
214 self
215 }
216
217 #[cfg(feature = "tmux_3_2")]
219 pub fn y(mut self, y: Size) -> Self {
220 self.y = Some(y);
221 self
222 }
223
224 #[cfg(feature = "tmux_3_2")]
226 pub fn shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
227 self.shell_command = Some(shell_command.into());
228 self
229 }
230
231 pub fn build(self) -> TmuxCommand<'a> {
232 let mut cmd = TmuxCommand::new();
233
234 cmd.name(DISPLAY_POPUP);
235
236 #[cfg(feature = "tmux_3_3")]
238 if self.no_border {
239 cmd.push_flag(B_UPPERCASE_KEY);
240 }
241
242 #[cfg(feature = "tmux_3_2")]
244 if self.close {
245 cmd.push_flag(C_UPPERCASE_KEY);
246 }
247
248 #[cfg(feature = "tmux_3_2")]
250 if self.close_on_exit {
251 cmd.push_flag(E_UPPERCASE_KEY);
252 }
253
254 #[cfg(feature = "tmux_3_2")]
256 if self.close_on_success {
257 cmd.push_flag(EE_UPPERCASE_KEY);
258 }
259
260 #[cfg(feature = "tmux_3_3")]
262 if let Some(border_lines) = self.border_lines {
263 cmd.push_option(B_LOWERCASE_KEY, border_lines.to_string());
264 }
265
266 #[cfg(feature = "tmux_3_2")]
268 if let Some(target_client) = self.target_client {
269 cmd.push_option(C_LOWERCASE_KEY, target_client);
270 }
271
272 #[cfg(feature = "tmux_3_2")]
274 if let Some(start_directory) = self.start_directory {
275 cmd.push_option(D_LOWERCASE_KEY, start_directory);
276 }
277
278 #[cfg(feature = "tmux_3_3")]
281 if let Some(environment) = self.environment {
282 cmd.push_option(
283 E_LOWERCASE_KEY,
284 format!("{}={}", environment.0, environment.1),
285 );
286 }
287
288 #[cfg(feature = "tmux_3_2")]
290 if let Some(height) = self.height {
291 cmd.push_option(H_LOWERCASE_KEY, height.to_string());
292 }
293
294 #[cfg(feature = "tmux_3_3")]
296 if let Some(style) = self.style {
297 cmd.push_option(S_LOWERCASE_KEY, style);
298 }
299
300 #[cfg(feature = "tmux_3_3")]
302 if let Some(border_style) = self.border_style {
303 cmd.push_option(S_UPPERCASE_KEY, border_style);
304 }
305
306 #[cfg(feature = "tmux_3_2")]
308 if let Some(target_pane) = self.target_pane {
309 cmd.push_option(T_LOWERCASE_KEY, target_pane);
310 }
311
312 #[cfg(feature = "tmux_3_3")]
314 if let Some(title) = self.title {
315 cmd.push_option(T_UPPERCASE_KEY, title);
316 }
317
318 #[cfg(feature = "tmux_3_2")]
320 if let Some(width) = self.width {
321 cmd.push_option(W_LOWERCASE_KEY, width.to_string());
322 }
323
324 #[cfg(feature = "tmux_3_2")]
326 if let Some(x) = self.x {
327 cmd.push_option(X_LOWERCASE_KEY, x.to_string());
328 }
329
330 #[cfg(feature = "tmux_3_2")]
332 if let Some(y) = self.y {
333 cmd.push_option(Y_LOWERCASE_KEY, y.to_string());
334 }
335
336 #[cfg(feature = "tmux_3_2")]
338 if let Some(shell_command) = self.shell_command {
339 cmd.push_param(shell_command);
340 }
341
342 cmd
343 }
344}