tmux_interface/commands/windows_and_panes/
rotate_window_macro.rs1#[macro_export]
17macro_rules! rotate_window {
18 (@cmd ($cmd:expr) -D, $($tail:tt)*) => {{
20 $crate::rotate_window!(@cmd ({
21 $cmd.down()
22 }) $($tail)*)
23 }};
24 (@cmd ($cmd:expr) -U, $($tail:tt)*) => {{
26 $crate::rotate_window!(@cmd ({
27 $cmd.up()
28 }) $($tail)*)
29 }};
30 (@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
32 $crate::rotate_window!(@cmd ({
33 $cmd.keep_zoomed()
34 }) $($tail)*)
35 }};
36 (@cmd ($cmd:expr) -t $target_window:expr, $($tail:tt)*) => {{
38 $crate::rotate_window!(@cmd ({
39 $cmd.target_window($target_window)
40 }) $($tail)*)
41 }};
42 (@cmd ($cmd:expr)) => {{
46 $cmd
47 }};
48 () => {{
49 $crate::RotateWindow::new()
50 }};
51 (($cmd:expr), $($tail:tt)*) => {{
52 $crate::rotate_window!(@cmd ($cmd) $($tail)*,)
53 }};
54 ($($tail:tt)*) => {{
55 $crate::rotate_window!(@cmd ({ $crate::RotateWindow::new() }) $($tail)*,)
56 }};
57}
58
59#[test]
60fn rotate_window_macro() {
61 use crate::TargetWindow;
62 use std::borrow::Cow;
63
64 let target_window = TargetWindow::Raw("1").to_string();
80
81 let rotate_window = rotate_window!();
82 #[cfg(feature = "tmux_0_8")]
83 let rotate_window = rotate_window!((rotate_window), -D);
84 #[cfg(feature = "tmux_0_8")]
85 let rotate_window = rotate_window!((rotate_window), -U);
86 #[cfg(feature = "tmux_3_1")]
87 let rotate_window = rotate_window!((rotate_window), -Z);
88 #[cfg(feature = "tmux_0_8")]
89 let rotate_window = rotate_window!((rotate_window), -t & target_window);
90
91 #[cfg(not(feature = "cmd_alias"))]
92 let cmd = "rotate-window";
93 #[cfg(feature = "cmd_alias")]
94 let cmd = "rotatew";
95
96 let mut s = Vec::new();
97 s.push(cmd);
98 #[cfg(feature = "tmux_0_8")]
99 s.push("-D");
100 #[cfg(feature = "tmux_0_8")]
101 s.push("-U");
102 #[cfg(feature = "tmux_3_1")]
103 s.push("-Z");
104 #[cfg(feature = "tmux_0_8")]
105 s.extend_from_slice(&["-t", "1"]);
106 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
107
108 let rotate_window = rotate_window.build().to_vec();
109
110 assert_eq!(rotate_window, s);
111}