tmux_interface/commands/windows_and_panes/
resize_window_macro.rs1#[macro_export]
14macro_rules! resize_window {
15 (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
17 $crate::resize_window!(@cmd ({
18 $cmd.smallest()
19 }) $($tail)*)
20 }};
21
22 (@cmd ($cmd:expr) -A, $($tail:tt)*) => {{
24 $crate::resize_window!(@cmd ({
25 $cmd.largest()
26 }) $($tail)*)
27 }};
28
29 (@cmd ($cmd:expr) -D, $($tail:tt)*) => {{
31 $crate::resize_window!(@cmd ({
32 $cmd.down()
33 }) $($tail)*)
34 }};
35
36 (@cmd ($cmd:expr) -L, $($tail:tt)*) => {{
38 $crate::resize_window!(@cmd ({
39 $cmd.left()
40 }) $($tail)*)
41 }};
42
43 (@cmd ($cmd:expr) -R, $($tail:tt)*) => {{
45 $crate::resize_window!(@cmd ({
46 $cmd.right()
47 }) $($tail)*)
48 }};
49
50 (@cmd ($cmd:expr) -U, $($tail:tt)*) => {{
52 $crate::resize_window!(@cmd ({
53 $cmd.up()
54 }) $($tail)*)
55 }};
56
57 (@cmd ($cmd:expr) -t $target_window:expr, $($tail:tt)*) => {{
59 $crate::resize_window!(@cmd ({
60 $cmd.target_window($target_window)
61 }) $($tail)*)
62 }};
63
64 (@cmd ($cmd:expr) -x $width:expr, $($tail:tt)*) => {{
66 $crate::resize_window!(@cmd ({
67 $cmd.width($width)
68 }) $($tail)*)
69 }};
70
71 (@cmd ($cmd:expr) -y $height:expr, $($tail:tt)*) => {{
73 $crate::resize_window!(@cmd ({
74 $cmd.height($height)
75 }) $($tail)*)
76 }};
77
78 (@cmd ($cmd:expr) $adjustment:expr, $($tail:tt)*) => {{
80 $crate::resize_window!(@cmd ({
81 $cmd.adjustment($adjustment)
82 }) $($tail)*)
83 }};
84
85 (@cmd ($cmd:expr)) => {{
89 $cmd
90 }};
91 () => {{
92 $crate::ResizeWindow::new()
93 }};
94 (($cmd:expr), $($tail:tt)*) => {{
95 $crate::resize_window!(@cmd ($cmd) $($tail)*,)
96 }};
97 ($($tail:tt)*) => {{
98 $crate::resize_window!(@cmd ({ $crate::ResizeWindow::new() }) $($tail)*,)
99 }};
100}
101
102#[test]
103fn resize_window_macro() {
104 use std::borrow::Cow;
105
106 let resize_window = resize_window!();
117 #[cfg(feature = "tmux_2_9")]
118 let resize_window = resize_window!((resize_window), -a);
119 #[cfg(feature = "tmux_2_9")]
120 let resize_window = resize_window!((resize_window), -A);
121 #[cfg(feature = "tmux_2_9")]
122 let resize_window = resize_window!((resize_window), -D);
123 #[cfg(feature = "tmux_2_9")]
124 let resize_window = resize_window!((resize_window), -L);
125 #[cfg(feature = "tmux_2_9")]
126 let resize_window = resize_window!((resize_window), -R);
127 #[cfg(feature = "tmux_2_9")]
128 let resize_window = resize_window!((resize_window), -U);
129 #[cfg(feature = "tmux_2_9")]
130 let resize_window = resize_window!((resize_window), -t "1");
131 #[cfg(feature = "tmux_2_9")]
132 let resize_window = resize_window!((resize_window), -x 2);
133 #[cfg(feature = "tmux_2_9")]
134 let resize_window = resize_window!((resize_window), -y 3);
135 #[cfg(feature = "tmux_2_9")]
136 let resize_window = resize_window!((resize_window), "4");
137
138 #[cfg(not(feature = "cmd_alias"))]
139 let cmd = "resize-window";
140 #[cfg(feature = "cmd_alias")]
141 let cmd = "resizew";
142
143 let mut s = Vec::new();
144 s.push(cmd);
145 #[cfg(feature = "tmux_2_9")]
146 s.push("-a");
147 #[cfg(feature = "tmux_2_9")]
148 s.push("-A");
149 #[cfg(feature = "tmux_2_9")]
150 s.push("-D");
151 #[cfg(feature = "tmux_2_9")]
152 s.push("-L");
153 #[cfg(feature = "tmux_2_9")]
154 s.push("-R");
155 #[cfg(feature = "tmux_2_9")]
156 s.push("-U");
157 #[cfg(feature = "tmux_2_9")]
158 s.extend_from_slice(&["-t", "1"]);
159 #[cfg(feature = "tmux_2_9")]
160 s.extend_from_slice(&["-x", "2"]);
161 #[cfg(feature = "tmux_2_9")]
162 s.extend_from_slice(&["-y", "3"]);
163 #[cfg(feature = "tmux_2_9")]
164 s.push("4");
165 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
166 let resize_window = resize_window.build().to_vec();
167
168 assert_eq!(resize_window, s);
169}