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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
use crate::Error;
#[cfg(feature = "tmux_1_8")]
use crate::PaneTabs;
pub const PANE_ACTIVE: u64 = 1;
pub const PANE_AT_BOTTOM: u64 = 1 << 1;
pub const PANE_AT_LEFT: u64 = 1 << 2;
pub const PANE_AT_RIGHT: u64 = 1 << 3;
pub const PANE_AT_TOP: u64 = 1 << 4;
pub const PANE_BOTTOM: u64 = 1 << 5;
pub const PANE_CURRENT_COMMAND: u64 = 1 << 6;
pub const PANE_CURRENT_PATH: u64 = 1 << 7;
pub const PANE_DEAD: u64 = 1 << 8;
pub const PANE_DEAD_STATUS: u64 = 1 << 9;
pub const PANE_FORMAT: u64 = 1 << 10;
pub const PANE_HEIGHT: u64 = 1 << 11;
pub const PANE_ID: u64 = 1 << 12;
pub const PANE_IN_MODE: u64 = 1 << 13;
pub const PANE_INDEX: u64 = 1 << 14;
pub const PANE_INPUT_OFF: u64 = 1 << 15;
pub const PANE_LEFT: u64 = 1 << 16;
pub const PANE_MARKED: u64 = 1 << 17;
pub const PANE_MARKED_SET: u64 = 1 << 18;
pub const PANE_MODE: u64 = 1 << 19;
pub const PANE_PATH: u64 = 1 << 20;
pub const PANE_PID: u64 = 1 << 21;
pub const PANE_PIPE: u64 = 1 << 22;
pub const PANE_RIGHT: u64 = 1 << 23;
pub const PANE_SEARCH_STRING: u64 = 1 << 24;
pub const PANE_START_COMMMAND: u64 = 1 << 25;
pub const PANE_START_PATH: u64 = 1 << 26;
pub const PANE_SYNCHRONIZED: u64 = 1 << 27;
pub const PANE_TABS: u64 = 1 << 28;
pub const PANE_TITLE: u64 = 1 << 29;
pub const PANE_TOP: u64 = 1 << 30;
pub const PANE_TTY: u64 = 1 << 31;
pub const PANE_WIDTH: u64 = 1 << 32;
#[cfg(all(feature = "tmux_1_6", not(feature = "tmux_1_7")))]
pub const PANE_FLAGS_NUM: usize = 10;
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_1_8")))]
pub const PANE_FLAGS_NUM: usize = 12;
#[cfg(all(feature = "tmux_1_8", not(feature = "tmux_1_9")))]
pub const PANE_FLAGS_NUM: usize = 15;
#[cfg(all(feature = "tmux_1_9", not(feature = "tmux_1_9a")))]
pub const PANE_FLAGS_NUM: usize = 16;
#[cfg(all(feature = "tmux_1_9a", not(feature = "tmux_2_0")))]
pub const PANE_FLAGS_NUM: usize = 16;
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_1")))]
pub const PANE_FLAGS_NUM: usize = 21;
#[cfg(all(feature = "tmux_2_1", not(feature = "tmux_2_2")))]
pub const PANE_FLAGS_NUM: usize = 21;
#[cfg(all(feature = "tmux_2_2", not(feature = "tmux_2_3")))]
pub const PANE_FLAGS_NUM: usize = 21;
#[cfg(all(feature = "tmux_2_3", not(feature = "tmux_2_4")))]
pub const PANE_FLAGS_NUM: usize = 21;
#[cfg(all(feature = "tmux_2_4", not(feature = "tmux_2_5")))]
pub const PANE_FLAGS_NUM: usize = 21;
#[cfg(all(feature = "tmux_2_5", not(feature = "tmux_2_6")))]
pub const PANE_FLAGS_NUM: usize = 23;
#[cfg(all(feature = "tmux_2_6", not(feature = "tmux_2_7")))]
pub const PANE_FLAGS_NUM: usize = 29;
#[cfg(all(feature = "tmux_2_7", not(feature = "tmux_2_8")))]
pub const PANE_FLAGS_NUM: usize = 29;
#[cfg(all(feature = "tmux_2_8", not(feature = "tmux_2_9")))]
pub const PANE_FLAGS_NUM: usize = 29;
#[cfg(all(feature = "tmux_2_9", not(feature = "tmux_2_9a")))]
pub const PANE_FLAGS_NUM: usize = 29;
#[cfg(all(feature = "tmux_2_9a", not(feature = "tmux_3_0")))]
pub const PANE_FLAGS_NUM: usize = 29;
#[cfg(all(feature = "tmux_3_0", not(feature = "tmux_3_0a")))]
pub const PANE_FLAGS_NUM: usize = 31;
#[cfg(all(feature = "tmux_3_0a", not(feature = "tmux_3_1")))]
pub const PANE_FLAGS_NUM: usize = 31;
#[cfg(all(feature = "tmux_3_1", not(feature = "tmux_3_1a")))]
pub const PANE_FLAGS_NUM: usize = 32;
#[cfg(all(feature = "tmux_3_1a", not(feature = "tmux_3_1b")))]
pub const PANE_FLAGS_NUM: usize = 32;
#[cfg(all(feature = "tmux_3_1b", not(feature = "tmux_X_X")))]
pub const PANE_FLAGS_NUM: usize = 32;
#[cfg(feature = "tmux_X_X")]
pub const PANE_FLAGS_NUM: usize = 32;
pub const PANE_NONE: u64 = 0;
pub const PANE_ALL: u64 = PANE_ACTIVE
| PANE_AT_BOTTOM
| PANE_AT_LEFT
| PANE_AT_RIGHT
| PANE_AT_TOP
| PANE_BOTTOM
| PANE_CURRENT_COMMAND
| PANE_CURRENT_PATH
| PANE_DEAD
| PANE_DEAD_STATUS
| PANE_FORMAT
| PANE_HEIGHT
| PANE_ID
| PANE_IN_MODE
| PANE_INDEX
| PANE_INPUT_OFF
| PANE_LEFT
| PANE_MARKED
| PANE_MARKED_SET
| PANE_MODE
| PANE_PATH
| PANE_PID
| PANE_PIPE
| PANE_RIGHT
| PANE_SEARCH_STRING
| PANE_START_COMMMAND
| PANE_START_PATH
| PANE_SYNCHRONIZED
| PANE_TABS
| PANE_TITLE
| PANE_TOP
| PANE_TTY
| PANE_WIDTH;
pub const PANE_VARS_SEPARATOR: &str = "'";
pub const PANE_VARS: [(&str, u64, fn(p: &mut Pane, t: &str)); PANE_FLAGS_NUM] = [
#[cfg(feature = "tmux_1_6")]
("pane_active", PANE_ACTIVE, |p, t| {
p.active = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_6")]
("pane_at_bottom", PANE_AT_BOTTOM, |p, t| {
p.at_bottom = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_6")]
("pane_at_left", PANE_AT_LEFT, |p, t| {
p.at_left = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_6")]
("pane_at_right", PANE_AT_RIGHT, |p, t| {
p.at_right = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_6")]
("pane_at_top", PANE_AT_TOP, |p, t| {
p.at_top = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_0")]
("pane_bottom", PANE_BOTTOM, |p, t| p.bottom = t.parse().ok()),
#[cfg(feature = "tmux_1_8")]
("pane_current_command", PANE_CURRENT_COMMAND, |p, t| {
p.current_command = t.parse().ok()
}),
#[cfg(feature = "tmux_1_7")]
("pane_current_path", PANE_CURRENT_PATH, |p, t| {
p.current_path = t.parse().ok()
}),
#[cfg(feature = "tmux_1_6")]
("pane_dead", PANE_DEAD, |p, t| {
p.dead = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_0")]
("pane_dead_status", PANE_DEAD, |p, t| {
p.dead_status = t.parse().ok()
}),
#[cfg(feature = "tmux_2_6")]
("pane_format", PANE_FORMAT, |p, t| {
p.format = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_1_6")]
("pane_height", PANE_HEIGHT, |p, t| p.height = t.parse().ok()),
#[cfg(feature = "tmux_1_6")]
("pane_id", PANE_ID, |p, t| p.id = t[1..].parse().ok()),
#[cfg(feature = "tmux_1_8")]
("pane_in_mode", PANE_IN_MODE, |p, t| {
p.in_mode = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_1_7")]
("pane_index", PANE_INDEX, |p, t| p.index = t.parse().ok()),
#[cfg(feature = "tmux_2_0")]
("pane_input_off", PANE_INPUT_OFF, |p, t| {
p.input_off = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_0")]
("pane_left", PANE_LEFT, |p, t| p.left = t.parse().ok()),
#[cfg(feature = "tmux_3_0")]
("pane_marked", PANE_MARKED, |p, t| {
p.marked = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_3_0")]
("pane_marked_set", PANE_MARKED_SET, |p, t| {
p.marked_set = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_5")]
("pane_mode", PANE_MODE, |p, t| p.mode = t.parse().ok()),
#[cfg(feature = "tmux_3_1")]
("pane_path", PANE_PATH, |p, t| p.path = t.parse().ok()),
#[cfg(feature = "tmux_1_6")]
("pane_pid", PANE_PID, |p, t| p.pid = t.parse().ok()),
#[cfg(feature = "tmux_2_6")]
("pane_pipe", PANE_PIPE, |p, t| {
p.pipe = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_2_0")]
("pane_right", PANE_RIGHT, |p, t| p.right = t.parse().ok()),
#[cfg(feature = "tmux_2_5")]
("pane_search_string", PANE_SEARCH_STRING, |p, t| {
p.search_string = t.parse().ok()
}),
#[cfg(feature = "tmux_1_6")]
("pane_start_command", PANE_START_COMMMAND, |p, t| {
p.start_command = t.parse().ok()
}),
#[cfg(all(feature = "tmux_1_6", not(feature = "tmux_2_0")))]
("pane_start_path", PANE_START_PATH, |p, t| {
p.start_path = t.parse().ok()
}),
#[cfg(feature = "tmux_1_9")]
("pane_synchronized", PANE_SYNCHRONIZED, |p, t| {
p.synchronized = t.parse::<usize>().map(|b| b == 1).ok()
}),
#[cfg(feature = "tmux_1_8")]
("pane_tabs", PANE_TABS, |p, t| p.tabs = t.parse().ok()),
#[cfg(feature = "tmux_1_6")]
("pane_title", PANE_TITLE, |p, t| p.title = t.parse().ok()),
#[cfg(feature = "tmux_2_0")]
("pane_top", PANE_TOP, |p, t| p.top = t.parse().ok()),
#[cfg(feature = "tmux_1_6")]
("pane_tty", PANE_TTY, |p, t| p.tty = t.parse().ok()),
#[cfg(feature = "tmux_1_6")]
("pane_width", PANE_WIDTH, |p, t| p.width = t.parse().ok()),
];
#[derive(Default, Clone, PartialEq, Debug)]
pub struct Pane {
#[cfg(feature = "tmux_1_6")]
pub active: Option<bool>,
#[cfg(feature = "tmux_2_6")]
pub at_bottom: Option<bool>,
#[cfg(feature = "tmux_2_6")]
pub at_left: Option<bool>,
#[cfg(feature = "tmux_2_6")]
pub at_right: Option<bool>,
#[cfg(feature = "tmux_2_6")]
pub at_top: Option<bool>,
#[cfg(feature = "tmux_2_0")]
pub bottom: Option<usize>,
#[cfg(feature = "tmux_1_8")]
pub current_command: Option<String>,
#[cfg(feature = "tmux_1_7")]
pub current_path: Option<String>,
#[cfg(feature = "tmux_1_6")]
pub dead: Option<bool>,
#[cfg(feature = "tmux_2_0")]
pub dead_status: Option<usize>,
#[cfg(feature = "tmux_2_6")]
pub format: Option<bool>,
#[cfg(feature = "tmux_1_6")]
pub height: Option<usize>,
#[cfg(feature = "tmux_1_6")]
pub id: Option<usize>,
#[cfg(feature = "tmux_1_8")]
pub in_mode: Option<bool>,
#[cfg(feature = "tmux_1_7")]
pub index: Option<usize>,
#[cfg(feature = "tmux_2_0")]
pub input_off: Option<bool>,
#[cfg(feature = "tmux_2_0")]
pub left: Option<usize>,
#[cfg(feature = "tmux_3_0")]
pub marked: Option<bool>,
#[cfg(feature = "tmux_3_0")]
pub marked_set: Option<bool>,
#[cfg(feature = "tmux_2_5")]
pub mode: Option<usize>,
#[cfg(feature = "tmux_3_1")]
pub path: Option<String>,
#[cfg(feature = "tmux_1_6")]
pub pid: Option<usize>,
#[cfg(feature = "tmux_2_6")]
pub pipe: Option<bool>,
#[cfg(feature = "tmux_2_0")]
pub right: Option<usize>,
#[cfg(feature = "tmux_2_5")]
pub search_string: Option<usize>,
#[cfg(feature = "tmux_1_6")]
pub start_command: Option<usize>,
#[cfg(all(feature = "tmux_1_6", not(feature = "tmux_2_0")))]
pub start_path: Option<usize>,
#[cfg(feature = "tmux_1_9")]
pub synchronized: Option<bool>,
#[cfg(feature = "tmux_1_8")]
pub tabs: Option<PaneTabs>,
#[cfg(feature = "tmux_1_6")]
pub title: Option<String>,
#[cfg(feature = "tmux_2_0")]
pub top: Option<usize>,
#[cfg(feature = "tmux_1_6")]
pub tty: Option<String>,
#[cfg(feature = "tmux_1_6")]
pub width: Option<usize>,
}
impl Pane {
pub fn new() -> Self {
Default::default()
}
pub fn from_str(pane_str: &str, bitflags: u64) -> Result<Self, Error> {
let pv: Vec<&str> = pane_str.split(PANE_VARS_SEPARATOR).collect();
let mut pv = pv.iter();
let mut p = Pane::new();
for var in PANE_VARS.iter() {
if bitflags & var.1 == var.1 {
if let Some(part) = pv.next() {
if !part.is_empty() {
var.2(&mut p, part);
}
}
}
}
Ok(p)
}
}