tmux_interface/commands/windows_and_panes/
rotate_window_macro.rs

1/// Rotate the positions of the panes within a window
2///
3/// # Manual
4///
5/// tmux ^3.1:
6/// ```text
7/// rotate-window [-DUZ] [-t target-window]
8/// (alias: rotatew)
9/// ```
10///
11/// tmux ^0.8:
12/// ```text
13/// rotate-window [-DU] [-t target-window]
14/// (alias: rotatew)
15/// ```
16#[macro_export]
17macro_rules! rotate_window {
18    // `[-D]`
19    (@cmd ($cmd:expr) -D, $($tail:tt)*) => {{
20        $crate::rotate_window!(@cmd ({
21            $cmd.down()
22        }) $($tail)*)
23    }};
24    // `[-U]`
25    (@cmd ($cmd:expr) -U, $($tail:tt)*) => {{
26        $crate::rotate_window!(@cmd ({
27            $cmd.up()
28        }) $($tail)*)
29    }};
30    // `[-Z]`
31    (@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
32        $crate::rotate_window!(@cmd ({
33            $cmd.keep_zoomed()
34        }) $($tail)*)
35    }};
36    // `[-t target-window]`
37    (@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) -$unknown:tt, $($tail:tt)*) => {{
43        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
44    //}};
45    (@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    // Rotate the positions of the panes within a window
65    //
66    // # Manual
67    //
68    // tmux ^3.1:
69    // ```text
70    // rotate-window [-DUZ] [-t target-window]
71    // (alias: rotatew)
72    // ```
73    //
74    // tmux ^0.8:
75    // ```text
76    // rotate-window [-DU] [-t target-window]
77    // (alias: rotatew)
78    // ```
79    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}