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
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type CaptureP<'a> = CapturePane<'a>;
/// # Manual
///
/// tmux ^3.4:
/// ```text
/// capture-pane [-aAepPqCJNT] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]
/// (alias: capturep)
/// ```
///
/// tmux ^3.1:
/// ```text
/// capture-pane [-aepPqCJN] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]
/// (alias: capturep)
/// ```
///
/// tmux ^2.4:
/// ```text
/// capture-pane [-aepPqCJ] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]
/// (alias: capturep)
/// ```
///
/// tmux ^1.8:
/// ```text
/// capture-pane [-aepPq] [-b buffer-name] [-E end-line] [-S start-line] [-t target-pane]
/// (alias: capturep)
/// ```
///
/// tmux ^1.5:
/// ```text
/// capture-pane [-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]
/// (alias: capturep)
/// ```
///
/// tmux ^1.2:
/// ```text
/// capture-pane [-b buffer-index] [-t target-pane]
/// (alias: capturep)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct CapturePane<'a> {
/// `[-a]` - the alternate screen is used, and the history is not accessible
#[cfg(feature = "tmux_1_8")]
pub alternate_screen: bool,
/// `[-e]` - the output includes escape sequences for text and background attributes
#[cfg(feature = "tmux_1_8")]
pub escape_sequences: bool,
/// `[-p]` - the output goes to stdout
#[cfg(feature = "tmux_1_8")]
pub stdout: bool,
/// `[-P]` - capture only any output that the pane has received that is the beginning of an
/// as-yet incomplete escape sequence
#[cfg(feature = "tmux_1_8")]
pub pane: bool,
/// `[-q]` - quiet
#[cfg(feature = "tmux_1_8")]
pub quiet: bool,
/// `[-C]` - escape non-printable characters as octal \xxx
#[cfg(feature = "tmux_2_4")]
pub escape_non_printable: bool,
/// `[-J]` - preserve trailing spaces and joins any wrapped lines
#[cfg(feature = "tmux_2_4")]
pub join: bool,
/// `[-N]` - preserves trailing spaces at each line's end
#[cfg(feature = "tmux_3_1")]
pub trailing_spaces: bool,
/// `[-T]` - ignores trailing positions that do not contain a character
#[cfg(feature = "tmux_3_4")]
pub ignore_trailing_positions: bool,
/// `[-b buffer-name]` - buffer-name
#[cfg(feature = "tmux_1_8")]
pub buffer_name: Option<Cow<'a, str>>,
// XXX: type?
/// `[-E end-line]` - specify the ending line number
#[cfg(feature = "tmux_1_5")]
pub end_line: Option<Cow<'a, str>>,
// XXX: type?
/// `[-S start-line]` - specify the starting line number
#[cfg(feature = "tmux_1_5")]
pub start_line: Option<Cow<'a, str>>,
/// `[-t target-pane]` - specify target-pane
#[cfg(feature = "tmux_1_2")]
pub target_pane: Option<Cow<'a, str>>,
}
impl<'a> CapturePane<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-a]` - the alternate screen is used, and the history is not accessible
#[cfg(feature = "tmux_1_8")]
pub fn alternate_screen(mut self) -> Self {
self.alternate_screen = true;
self
}
/// `[-e]` - the output includes escape sequences for text and background attributes
#[cfg(feature = "tmux_1_8")]
pub fn escape_sequences(mut self) -> Self {
self.escape_sequences = true;
self
}
/// `[-p]` - the output goes to stdout
#[cfg(feature = "tmux_1_8")]
pub fn stdout(mut self) -> Self {
self.stdout = true;
self
}
/// `[-P]` - capture only any output that the pane has received that is the beginning of an
/// as-yet incomplete escape sequence
#[cfg(feature = "tmux_1_8")]
pub fn pane(mut self) -> Self {
self.pane = true;
self
}
/// `[-q]` - quiet
#[cfg(feature = "tmux_1_8")]
pub fn quiet(mut self) -> Self {
self.quiet = true;
self
}
/// `[-C]` - escape non-printable characters as octal \xxx
#[cfg(feature = "tmux_2_4")]
pub fn escape_non_printable(mut self) -> Self {
self.escape_non_printable = true;
self
}
/// `[-J]` - preserve trailing spaces and joins any wrapped lines
#[cfg(feature = "tmux_2_4")]
pub fn join(mut self) -> Self {
self.join = true;
self
}
/// `[-N]` - preserves trailing spaces at each line's end
#[cfg(feature = "tmux_3_1")]
pub fn trailing_spaces(mut self) -> Self {
self.trailing_spaces = true;
self
}
/// `[-T]` - ignores trailing positions that do not contain a character
#[cfg(feature = "tmux_3_4")]
pub fn ignore_trailing_positions(mut self) -> Self {
self.ignore_trailing_positions = true;
self
}
/// `[-b buffer-name]` - buffer-name
#[cfg(feature = "tmux_1_8")]
pub fn buffer_name<S: Into<Cow<'a, str>>>(mut self, buffer_name: S) -> Self {
self.buffer_name = Some(buffer_name.into());
self
}
// XXX: type usize?
/// `[-E end-line]` - specify the ending line number
#[cfg(feature = "tmux_1_5")]
pub fn end_line<S: Into<Cow<'a, str>>>(mut self, end_line: S) -> Self {
self.end_line = Some(end_line.into());
self
}
// XXX: type usize?
/// `[-S start-line]` - specify the starting line number
#[cfg(feature = "tmux_1_5")]
pub fn start_line<S: Into<Cow<'a, str>>>(mut self, start_line: S) -> Self {
self.start_line = Some(start_line.into());
self
}
/// `[-t target-pane]` - specify target-pane
#[cfg(feature = "tmux_1_2")]
pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
self.target_pane = Some(target_pane.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(CAPTURE_PANE);
// `[-a]` - the alternate screen is used, and the history is not accessible
#[cfg(feature = "tmux_1_8")]
if self.alternate_screen {
cmd.push_flag(A_LOWERCASE_KEY);
}
// `[-e]` - the output includes escape sequences for text and background attributes
#[cfg(feature = "tmux_1_8")]
if self.escape_sequences {
cmd.push_flag(E_LOWERCASE_KEY);
}
// `[-p]` - the output goes to stdout
#[cfg(feature = "tmux_1_8")]
if self.stdout {
cmd.push_flag(P_LOWERCASE_KEY);
}
// `[-P]` - capture only any output that the pane has received that is the beginning of an
// as-yet incomplete escape sequence
#[cfg(feature = "tmux_1_8")]
if self.pane {
cmd.push_flag(P_UPPERCASE_KEY);
}
// `[-q]` - quiet
#[cfg(feature = "tmux_1_8")]
if self.quiet {
cmd.push_flag(Q_LOWERCASE_KEY);
}
// `[-C]` - escape non-printable characters as octal \xxx
#[cfg(feature = "tmux_2_4")]
if self.escape_non_printable {
cmd.push_flag(C_UPPERCASE_KEY);
}
// `[-J]` - preserve trailing spaces and joins any wrapped lines
#[cfg(feature = "tmux_2_4")]
if self.join {
cmd.push_flag(J_UPPERCASE_KEY);
}
// `[-N]` - preserves trailing spaces at each line's end
#[cfg(feature = "tmux_3_1")]
if self.trailing_spaces {
cmd.push_flag(N_UPPERCASE_KEY);
}
// `[-T]` - ignores trailing positions that do not contain a character
#[cfg(feature = "tmux_3_4")]
if self.ignore_trailing_positions {
cmd.push_flag(T_UPPERCASE_KEY);
}
// `[-b buffer-name]` - buffer-name
#[cfg(feature = "tmux_1_8")]
if let Some(buffer_name) = self.buffer_name {
cmd.push_option(B_LOWERCASE_KEY, buffer_name);
}
// `[-E end-line]` - specify the ending line number
#[cfg(feature = "tmux_1_5")]
if let Some(end_line) = self.end_line {
cmd.push_option(E_UPPERCASE_KEY, end_line);
}
// `[-S start-line]` - specify the starting line number
#[cfg(feature = "tmux_1_5")]
if let Some(start_line) = self.start_line {
cmd.push_option(S_UPPERCASE_KEY, start_line);
}
// `[-t target-pane]` - specify target-pane
#[cfg(feature = "tmux_1_2")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
cmd
}
}