tmux_interface/commands/windows_and_panes/
link_window_macro.rs1#[macro_export]
17macro_rules! link_window {
18 (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
20 $crate::link_window!(@cmd ({
21 $cmd.add()
22 }) $($tail)*)
23 }};
24 (@cmd ($cmd:expr) -d, $($tail:tt)*) => {{
26 $crate::link_window!(@cmd ({
27 $cmd.detached()
28 }) $($tail)*)
29 }};
30 (@cmd ($cmd:expr) -k, $($tail:tt)*) => {{
32 $crate::link_window!(@cmd ({
33 $cmd.kill()
34 }) $($tail)*)
35 }};
36 (@cmd ($cmd:expr) -s $src_window:expr, $($tail:tt)*) => {{
38 $crate::link_window!(@cmd ({
39 $cmd.src_window($src_window)
40 }) $($tail)*)
41 }};
42 (@cmd ($cmd:expr) -t $dst_window:expr, $($tail:tt)*) => {{
44 $crate::link_window!(@cmd ({
45 $cmd.dst_window($dst_window)
46 }) $($tail)*)
47 }};
48 (@cmd ($cmd:expr)) => {{
52 $cmd
53 }};
54 () => {{
55 $crate::LinkWindow::new()
56 }};
57 (($cmd:expr), $($tail:tt)*) => {{
58 $crate::link_window!(@cmd ($cmd) $($tail)*,)
59 }};
60 ($($tail:tt)*) => {{
61 $crate::link_window!(@cmd ({ $crate::LinkWindow::new() }) $($tail)*,)
62 }};
63}
64
65#[test]
66fn link_window_macro() {
67 use crate::TargetWindow;
68 use std::borrow::Cow;
69
70 let src_window = TargetWindow::Raw("1").to_string();
86 let dst_window = TargetWindow::Raw("2").to_string();
87
88 let link_window = link_window!();
89 #[cfg(feature = "tmux_2_1")]
90 let link_window = link_window!((link_window), -a);
91 #[cfg(feature = "tmux_0_8")]
92 let link_window = link_window!((link_window), -d);
93 #[cfg(feature = "tmux_0_8")]
94 let link_window = link_window!((link_window), -k);
95 #[cfg(feature = "tmux_0_8")]
96 let link_window = link_window!((link_window), -s & src_window);
97 #[cfg(feature = "tmux_0_8")]
98 let link_window = link_window!((link_window), -t & dst_window);
99
100 #[cfg(not(feature = "cmd_alias"))]
101 let cmd = "link-window";
102 #[cfg(feature = "cmd_alias")]
103 let cmd = "linkw";
104
105 let mut s = Vec::new();
106 s.push(cmd);
107 #[cfg(feature = "tmux_2_1")]
108 s.push("-a");
109 #[cfg(feature = "tmux_0_8")]
110 s.push("-d");
111 #[cfg(feature = "tmux_0_8")]
112 s.push("-k");
113 #[cfg(feature = "tmux_0_8")]
114 s.extend_from_slice(&["-s", "1"]);
115 #[cfg(feature = "tmux_0_8")]
116 s.extend_from_slice(&["-t", "2"]);
117 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
118
119 let link_window = link_window.build().to_vec();
120
121 assert_eq!(link_window, s);
122}