tmux_interface/commands/windows_and_panes/
link_window_macro.rs

1/// Link the window at src-window to the specified dst-window
2///
3/// # Manual
4///
5/// tmux ^2.1:
6/// ```text
7/// link-window [-adk] [-s src-window] [-t dst-window]
8/// (alias: linkw)
9/// ```
10///
11/// tmux ^0.8:
12/// ```text
13/// link-window [-dk] [-s src-window] [-t dst-window]
14/// (alias: linkw)
15/// ```
16#[macro_export]
17macro_rules! link_window {
18    // `[-a]` - the window is moved to the next index up
19    (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
20        $crate::link_window!(@cmd ({
21            $cmd.add()
22        }) $($tail)*)
23    }};
24    // `[-d]` - the newly linked window is not selected
25    (@cmd ($cmd:expr) -d, $($tail:tt)*) => {{
26        $crate::link_window!(@cmd ({
27            $cmd.detached()
28        }) $($tail)*)
29    }};
30    // `[-k]` - if dst-window exists, it is killed, otherwise an error is generated
31    (@cmd ($cmd:expr) -k, $($tail:tt)*) => {{
32        $crate::link_window!(@cmd ({
33            $cmd.kill()
34        }) $($tail)*)
35    }};
36    // `[-s src-window]` - src-window
37    (@cmd ($cmd:expr) -s $src_window:expr, $($tail:tt)*) => {{
38        $crate::link_window!(@cmd ({
39            $cmd.src_window($src_window)
40        }) $($tail)*)
41    }};
42    // `[-t dst-window]` - dst-window
43    (@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) -$unknown:tt, $($tail:tt)*) => {{
49        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
50    //}};
51    (@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    // Link the window at src-window to the specified dst-window
71    //
72    // # Manual
73    //
74    // tmux ^2.1:
75    // ```text
76    // link-window [-adk] [-s src-window] [-t dst-window]
77    // (alias: linkw)
78    // ```
79    //
80    // tmux ^0.8:
81    // ```text
82    // link-window [-dk] [-s src-window] [-t dst-window]
83    // (alias: linkw)
84    // ```
85    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}