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
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type NewW<'a> = NewWindow<'a>;
/// Structure for creating new window, using `tmux new-window` command
///
/// # Manual
///
/// tmux ^3.2:
/// ```text
/// new-window [-abdkPS] [-c start-directory] [-e environment] [-F format] [-n window-name]
/// [-t target-window] [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^3.0:
/// ```text
/// new-window [-adkP] [-c start-directory] [-e environment] [-F format] [-n window-name] [-t
/// target-window] [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^1.7:
/// ```text
/// new-window [-adkP] [-c start-directory] [-F format] [-n window-name] [-t target-window]
/// [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^1.5:
/// ```text
/// new-window [-adkP] [-n window-name] [-t target-window] [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^1.3:
/// ```text
/// new-window [-adk] [-n window-name] [-t target-window] [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^1.2:
/// ```text
/// new-window [-dk] [-n window-name] [-t target-window] [shell-command]
/// (alias: neww)
/// ```
///
/// tmux ^1.0:
/// ```text
/// new-window [-dk] [-n window-name] [-t target-window] [command]
/// (alias: neww)
/// ```
///
/// tmux ^0.8:
/// ```text
/// new-window [-d] [-n window-name] [-t target-window] [command]
/// (alias: neww)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct NewWindow<'a> {
/// `[-a]` - new window is inserted at the next index up from the specified target-window
#[cfg(feature = "tmux_1_3")]
pub after: bool,
/// `[-b]` - new window is inserted at the next index before the specified target-window
#[cfg(feature = "tmux_3_2")]
pub before: bool,
/// `[-d]` - the session does not make the new window the current window
#[cfg(feature = "tmux_0_8")]
pub detached: bool,
/// `[-k]` - destroy if already exists
#[cfg(feature = "tmux_1_0")]
pub kill: bool,
/// `[-P]` - print information about the new window after it has been created
#[cfg(feature = "tmux_1_5")]
pub print: bool,
/// `[-S]` - is given and a window named window-name already exists, it is selected
#[cfg(feature = "tmux_3_2")]
pub select: bool,
/// `[-c start-directory]` - start-directory
#[cfg(feature = "tmux_1_7")]
pub start_directory: Option<Cow<'a, str>>,
/// `[-e environment]` - environment
#[cfg(feature = "tmux_3_0")]
pub environment: Option<Cow<'a, str>>,
/// `[-F format]` - format
#[cfg(feature = "tmux_1_7")]
pub format: Option<Cow<'a, str>>,
/// `[-n window-name]` - window-name
#[cfg(feature = "tmux_0_8")]
pub window_name: Option<Cow<'a, str>>,
/// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
pub target_window: Option<Cow<'a, str>>,
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_2")]
pub shell_command: Option<Cow<'a, str>>,
}
impl<'a> NewWindow<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-a]` - new window is inserted at the next index up from the specified target-window
#[cfg(feature = "tmux_1_3")]
pub fn after(mut self) -> Self {
self.after = true;
self
}
/// `[-b]` - new window is inserted at the next index before the specified target-window
#[cfg(feature = "tmux_3_2")]
pub fn before(mut self) -> Self {
self.before = true;
self
}
/// `[-d]` - the session does not make the new window the current window
#[cfg(feature = "tmux_0_8")]
pub fn detached(mut self) -> Self {
self.detached = true;
self
}
/// `[-k]` - destroy if already exists
#[cfg(feature = "tmux_1_0")]
pub fn kill(mut self) -> Self {
self.kill = true;
self
}
/// `[-P]` - print information about the new window after it has been created
#[cfg(feature = "tmux_1_5")]
pub fn print(mut self) -> Self {
self.print = true;
self
}
/// `[-S]` - is given and a window named window-name already exists, it is selected
#[cfg(feature = "tmux_3_2")]
pub fn select(mut self) -> Self {
self.select = true;
self
}
/// `[-c start-directory]` - start-directory
#[cfg(feature = "tmux_1_7")]
pub fn start_directory<S: Into<Cow<'a, str>>>(mut self, start_directory: S) -> Self {
self.start_directory = Some(start_directory.into());
self
}
/// `[-e environment]` - environment
#[cfg(feature = "tmux_3_0")]
pub fn environment<S: Into<Cow<'a, str>>>(mut self, environment: S) -> Self {
self.environment = Some(environment.into());
self
}
/// `[-F format]` - format
#[cfg(feature = "tmux_1_7")]
pub fn format<S: Into<Cow<'a, str>>>(mut self, format: S) -> Self {
self.format = Some(format.into());
self
}
/// `[-n window-name]` - window-name
#[cfg(feature = "tmux_0_8")]
pub fn window_name<S: Into<Cow<'a, str>>>(mut self, window_name: S) -> Self {
self.window_name = Some(window_name.into());
self
}
/// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
pub fn target_window<S: Into<Cow<'a, str>>>(mut self, target_window: S) -> Self {
self.target_window = Some(target_window.into());
self
}
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_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(NEW_WINDOW);
// `[-a]` - new window is inserted at the next index up from the specified target-window
#[cfg(feature = "tmux_1_3")]
if self.after {
cmd.push_flag(A_LOWERCASE_KEY);
}
// `[-b]` - new window is inserted at the next index before the specified target-window
#[cfg(feature = "tmux_3_2")]
if self.before {
cmd.push_flag(B_LOWERCASE_KEY);
}
// `[-d]` - the session does not make the new window the current window
#[cfg(feature = "tmux_0_8")]
if self.detached {
cmd.push_flag(D_LOWERCASE_KEY);
}
// `[-k]` - destroy if already exists
#[cfg(feature = "tmux_1_0")]
if self.kill {
cmd.push_flag(K_LOWERCASE_KEY);
}
// `[-P]` - print information about the new window after it has been created
#[cfg(feature = "tmux_1_5")]
if self.print {
cmd.push_flag(P_UPPERCASE_KEY);
}
// `[-S]` - is given and a window named window-name already exists, it is selected
#[cfg(feature = "tmux_3_2")]
if self.select {
cmd.push_flag(S_UPPERCASE_KEY);
}
// `[-c start-directory]` - start-directory
#[cfg(feature = "tmux_1_7")]
if let Some(start_directory) = self.start_directory {
cmd.push_option(C_LOWERCASE_KEY, start_directory);
}
// `[-e environment]` - environment
#[cfg(feature = "tmux_3_0")]
if let Some(environment) = self.environment {
cmd.push_option(E_LOWERCASE_KEY, environment);
}
// `[-F format]` - format
#[cfg(feature = "tmux_1_7")]
if let Some(format) = self.format {
cmd.push_option(F_UPPERCASE_KEY, format);
}
// `[-n window-name]` - window-name
#[cfg(feature = "tmux_0_8")]
if let Some(window_name) = self.window_name {
cmd.push_option(N_LOWERCASE_KEY, window_name);
}
// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_2")]
if let Some(shell_command) = self.shell_command {
cmd.push_param(shell_command);
}
cmd
}
}