1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
use crate::commands::constants::*;
#[cfg(feature = "tmux_3_3")]
use crate::commands::PopupBorderLinesType;
use crate::commands::Size;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Popup<'a> = DisplayPopup<'a>;
/// Structure for displaying a menu on target-client
///
/// # Manual
///
/// tmux ^3.3:
/// ```text
/// display-popup [-BCE] [-b border-lines] [-c target-client] [-d start-directory] [-e environment]
/// [-h height] [-s style] [-S border-style] [-t target-pane] [-T title] [-w width] [-x position]
/// [-y position] [shell-command]
/// ```
///
/// tmux ^3.2:
/// ```text
/// display-popup [-CE] [-c target-client] [-d start-directory] [-h height] [-t target-pane]
/// [-w width] [-x position] [-y position] [shell-command]
/// (alias: popup)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[cfg(feature = "tmux_3_2")]
pub struct DisplayPopup<'a> {
/// `[-B]` - not surround the popup by a border
#[cfg(feature = "tmux_3_3")]
pub no_border: bool,
/// `[-C]` - closes any popup on the client
#[cfg(feature = "tmux_3_2")]
pub close: bool,
/// `[-E]` - closes the popup automatically when shell-command exits
#[cfg(feature = "tmux_3_2")]
pub close_on_exit: bool,
/// `[-EE]` - closes the popup only if shell-command exited with success
#[cfg(feature = "tmux_3_2")]
pub close_on_success: bool,
/// `[-b border-lines]` - sets the type of border line for the popup. When -B is specified, the
/// -b option is ignored. See popup-border-lines for possible values for border-lines
#[cfg(feature = "tmux_3_3")]
pub border_lines: Option<PopupBorderLinesType>,
/// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_2")]
pub target_client: Option<Cow<'a, str>>,
/// `[-d start-directory]` -
#[cfg(feature = "tmux_3_2")]
pub start_directory: Option<Cow<'a, str>>,
// XXX: struct instead of tuple
/// `[-e environment]` - takes the form ‘VARIABLE=value’ and sets an environment variable for
/// the popup; it may be specified multiple times
#[cfg(feature = "tmux_3_3")]
pub environment: Option<(Cow<'a, str>, Cow<'a, str>)>,
/// `[-h height]` - height of the popup
#[cfg(feature = "tmux_3_2")]
pub height: Option<Size>,
// TODO: not imlemented!
/// `[-s style]` - sets the style for the popup
#[cfg(feature = "tmux_3_3")]
pub style: Option<Cow<'a, str>>,
// TODO: not imlemented!
/// `[-S border-style]` - sets the style for the popup border
#[cfg(feature = "tmux_3_3")]
pub border_style: Option<Cow<'a, str>>,
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_3_2")]
pub target_pane: Option<Cow<'a, str>>,
/// `[-T title]` - is a format for the popup title
#[cfg(feature = "tmux_3_3")]
pub title: Option<Cow<'a, str>>,
/// `[-w width]` - width of the popup
#[cfg(feature = "tmux_3_2")]
pub width: Option<Size>,
/// `[-x position]` - x position of the popup
#[cfg(feature = "tmux_3_2")]
pub x: Option<Size>,
/// `[-y position]` - y position of the popup
#[cfg(feature = "tmux_3_2")]
pub y: Option<Size>,
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_3_2")]
pub shell_command: Option<Cow<'a, str>>,
}
impl<'a> DisplayPopup<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-B]` - not surround the popup by a border
#[cfg(feature = "tmux_3_3")]
pub fn no_border(mut self) -> Self {
self.no_border = true;
self
}
/// `[-C]` - closes any popup on the client
#[cfg(feature = "tmux_3_2")]
pub fn close(mut self) -> Self {
self.close = true;
self
}
/// `[-E]` - closes the popup automatically when shell-command exits
#[cfg(feature = "tmux_3_2")]
pub fn close_on_exit(mut self) -> Self {
self.close_on_exit = true;
self
}
/// `[-EE]` - closes the popup only if shell-command exited with success
#[cfg(feature = "tmux_3_2")]
pub fn close_on_success(mut self) -> Self {
self.close_on_success = true;
self
}
/// `[-b border-lines]` - sets the type of border line for the popup. When -B is specified, the
/// -b option is ignored. See popup-border-lines for possible values for border-lines
#[cfg(feature = "tmux_3_3")]
pub fn border_lines(mut self, border_lines: PopupBorderLinesType) -> Self {
self.border_lines = Some(border_lines);
self
}
/// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_2")]
pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
self.target_client = Some(target_client.into());
self
}
/// `[-d start-directory]` - start-directory
#[cfg(feature = "tmux_3_2")]
pub fn start_directory<S: Into<Cow<'a, str>>>(mut self, start_directory: S) -> Self {
self.start_directory = Some(start_directory.into());
self
}
// TODO: vec
/// `[-e environment]` - takes the form ‘VARIABLE=value’ and sets an environment variable for
/// the popup; it may be specified multiple times
#[cfg(feature = "tmux_3_3")]
pub fn environment<S: Into<Cow<'a, str>>>(mut self, variable: S, value: S) -> Self {
self.environment = Some((variable.into(), value.into()));
self
}
/// `[-h height]` - height of the popup
#[cfg(feature = "tmux_3_2")]
pub fn height(mut self, height: Size) -> Self {
self.height = Some(height);
self
}
/// `[-s style]` - sets the style for the popup
#[cfg(feature = "tmux_3_3")]
pub fn style<S: Into<Cow<'a, str>>>(mut self, style: S) -> Self {
self.style = Some(style.into());
self
}
/// `[-S border-style]` - sets the style for the popup border
#[cfg(feature = "tmux_3_3")]
pub fn border_style<S: Into<Cow<'a, str>>>(mut self, border_style: S) -> Self {
self.border_style = Some(border_style.into());
self
}
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_3_2")]
pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
self.target_pane = Some(target_pane.into());
self
}
/// `[-T title]` - is a format for the popup title
#[cfg(feature = "tmux_3_3")]
pub fn title<S: Into<Cow<'a, str>>>(mut self, title: S) -> Self {
self.title = Some(title.into());
self
}
/// `[-w width]` - width of the pane
#[cfg(feature = "tmux_3_2")]
pub fn width(mut self, width: Size) -> Self {
self.width = Some(width);
self
}
/// `[-x position]` - x position of the pane
#[cfg(feature = "tmux_3_2")]
pub fn x(mut self, x: Size) -> Self {
self.x = Some(x);
self
}
/// `[-y position]` - y position of the pane
#[cfg(feature = "tmux_3_2")]
pub fn y(mut self, y: Size) -> Self {
self.y = Some(y);
self
}
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_3_2")]
pub fn shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
self.shell_command = Some(shell_command.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(DISPLAY_POPUP);
// `[-B]` - not surround the popup by a border
#[cfg(feature = "tmux_3_3")]
if self.no_border {
cmd.push_flag(B_UPPERCASE_KEY);
}
// `[-C]` - closes any popup on the client
#[cfg(feature = "tmux_3_2")]
if self.close {
cmd.push_flag(C_UPPERCASE_KEY);
}
// `[-E]` - closes the popup automatically when shell-command exits
#[cfg(feature = "tmux_3_2")]
if self.close_on_exit {
cmd.push_flag(E_UPPERCASE_KEY);
}
// `[-EE]` - closes the popup only if shell-command exited with success
#[cfg(feature = "tmux_3_2")]
if self.close_on_success {
cmd.push_flag(EE_UPPERCASE_KEY);
}
// `[-b border-lines]` - sets the type of border line for the popup
#[cfg(feature = "tmux_3_3")]
if let Some(border_lines) = self.border_lines {
cmd.push_option(B_LOWERCASE_KEY, border_lines.to_string());
}
// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_2")]
if let Some(target_client) = self.target_client {
cmd.push_option(C_LOWERCASE_KEY, target_client);
}
// `[-d start-directory]` - start-directory
#[cfg(feature = "tmux_3_2")]
if let Some(start_directory) = self.start_directory {
cmd.push_option(D_LOWERCASE_KEY, start_directory);
}
// `[-e environment]` - takes the form ‘VARIABLE=value’ and sets an environment variable for
// the popup; it may be specified multiple times
#[cfg(feature = "tmux_3_3")]
if let Some(environment) = self.environment {
cmd.push_option(
E_LOWERCASE_KEY,
format!("{}={}", environment.0, environment.1),
);
}
// `[-h height]` - height of the popup
#[cfg(feature = "tmux_3_2")]
if let Some(height) = self.height {
cmd.push_option(H_LOWERCASE_KEY, height.to_string());
}
// `[-s style]` - sets the style for the popup
#[cfg(feature = "tmux_3_3")]
if let Some(style) = self.style {
cmd.push_option(S_LOWERCASE_KEY, style);
}
// `[-S border-style]` - sets the style for the popup border
#[cfg(feature = "tmux_3_3")]
if let Some(border_style) = self.border_style {
cmd.push_option(S_UPPERCASE_KEY, border_style);
}
// `[-t target-pane]` - target-client
#[cfg(feature = "tmux_3_2")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
// `[-T title]` - is a format for the popup title
#[cfg(feature = "tmux_3_3")]
if let Some(title) = self.title {
cmd.push_option(T_UPPERCASE_KEY, title);
}
// `[-w width]` - width of the popup
#[cfg(feature = "tmux_3_2")]
if let Some(width) = self.width {
cmd.push_option(W_LOWERCASE_KEY, width.to_string());
}
// `[-x position]` - x position of the popup
#[cfg(feature = "tmux_3_2")]
if let Some(x) = self.x {
cmd.push_option(X_LOWERCASE_KEY, x.to_string());
}
// `[-y position]` - y position of the popup
#[cfg(feature = "tmux_3_2")]
if let Some(y) = self.y {
cmd.push_option(Y_LOWERCASE_KEY, y.to_string());
}
// `[shell-command]` - shell-command
#[cfg(feature = "tmux_3_2")]
if let Some(shell_command) = self.shell_command {
cmd.push_param(shell_command);
}
cmd
}
}