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
/// Search for the fnmatch(3) pattern `match-string` in window names,
/// titles, and visible content (but not history)
///
/// # Manual
///
/// tmux ^3.0:
/// ```text
/// find-window [-rCNTZ] [-t target-pane] match-string
/// (alias: findw)
///
/// tmux ^2.6:
/// ```text
/// find-window [-CNT] [-t target-pane] match-string
/// (alias: findw)
///
/// tmux ^1.7:
/// ```text
/// find-window [-CNT] [-F format] [-t target-pane] match-string
/// (alias: findw)
///
/// tmux ^0.8:
/// ```text
/// find-window [-t target-pane] match-string
/// (alias: findw)
/// ```
#[macro_export]
macro_rules! find_window {
// `[-r]` - regular expression
(@cmd ($cmd:expr) -r, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.regex()
}) $($tail)*)
}};
// `[-C]` - match only visible window contents
(@cmd ($cmd:expr) -C, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.only_visible()
}) $($tail)*)
}};
// `[-N]` - match only the window name
(@cmd ($cmd:expr) -N, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.only_name()
}) $($tail)*)
}};
// `[-T]` - match only the window title
(@cmd ($cmd:expr) -T, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.only_title()
}) $($tail)*)
}};
// `[-Z]` - zoom the pane
(@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.zoom()
}) $($tail)*)
}};
// `[-t target-pane]` - target-pane
(@cmd ($cmd:expr) -t $target_pane:expr, $($tail:tt)*) => {{
$crate::find_window!(@cmd ({
$cmd.target_pane($target_pane)
}) $($tail)*)
}};
//(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
//::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
//}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::FindWindow::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::find_window!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::find_window!(@cmd ({ $crate::FindWindow::new() }) $($tail)*,)
}};
}
#[test]
fn find_window_macro() {
use crate::TargetPane;
use std::borrow::Cow;
// # Manual
//
// tmux ^3.0:
// ```text
// find-window [-rCNTZ] [-t target-pane] match-string
// (alias: findw)
//
// tmux ^2.6:
// ```text
// find-window [-CNT] [-t target-pane] match-string
// (alias: findw)
//
// tmux ^1.7:
// ```text
// find-window [-CNT] [-F format] [-t target-pane] match-string
// (alias: findw)
//
// tmux ^0.8:
// ```text
// find-window [-t target-pane] match-string
// (alias: findw)
// ```
let target_pane = TargetPane::Raw("1").to_string();
let find_window = find_window!();
#[cfg(feature = "tmux_3_0")]
let find_window = find_window!((find_window), -r);
#[cfg(feature = "tmux_1_7")]
let find_window = find_window!((find_window), -C);
#[cfg(feature = "tmux_1_7")]
let find_window = find_window!((find_window), -N);
#[cfg(feature = "tmux_1_7")]
let find_window = find_window!((find_window), -T);
#[cfg(feature = "tmux_3_0")]
let find_window = find_window!((find_window), -Z);
#[cfg(feature = "tmux_0_8")]
let find_window = find_window!((find_window), -t & target_pane);
#[cfg(not(feature = "cmd_alias"))]
let cmd = "find-window";
#[cfg(feature = "cmd_alias")]
let cmd = "findw";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_3_0")]
s.push("-r");
#[cfg(feature = "tmux_1_7")]
s.push("-C");
#[cfg(feature = "tmux_1_7")]
s.push("-N");
#[cfg(feature = "tmux_1_7")]
s.push("-T");
#[cfg(feature = "tmux_3_0")]
s.push("-Z");
#[cfg(feature = "tmux_0_8")]
s.extend_from_slice(&["-t", "1"]);
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let find_window = find_window.build().to_vec();
assert_eq!(find_window, s);
}