tmux_interface/commands/windows_and_panes/
previous_layout_macro.rs

1/// Move to the previous layout in the session
2///
3/// # Manual
4///
5/// tmux ^1.3:
6/// ```text
7/// previous-layout [-t target-window]
8/// (alias: prevl)
9/// ```
10#[macro_export]
11macro_rules! previous_layout {
12    // `[-t target-window]`
13    (@cmd ($cmd:expr) -t $target_window:expr, $($tail:tt)*) => {{
14        $crate::previous_layout!(@cmd ({
15            $cmd.target_window($target_window)
16        }) $($tail)*)
17    }};
18    //(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
19        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
20    //}};
21    (@cmd ($cmd:expr)) => {{
22        $cmd
23    }};
24    () => {{
25        $crate::PreviousLayout::new()
26    }};
27    (($cmd:expr), $($tail:tt)*) => {{
28        $crate::previous_layout!(@cmd ($cmd) $($tail)*,)
29    }};
30    ($($tail:tt)*) => {{
31        $crate::previous_layout!(@cmd ({ $crate::PreviousLayout::new() }) $($tail)*,)
32    }};
33}
34
35#[test]
36fn previous_layout_macro() {
37    use crate::TargetWindow;
38    use std::borrow::Cow;
39
40    // Move to the previous layout in the session
41    //
42    // # Manual
43    //
44    // tmux ^1.3:
45    // ```text
46    // previous-layout [-t target-window]
47    // (alias: prevl)
48    // ```
49
50    let target_window = TargetWindow::Raw("1").to_string();
51
52    let previous_layout = previous_layout!();
53    #[cfg(feature = "tmux_1_3")]
54    let previous_layout = previous_layout!((previous_layout), -t & target_window);
55
56    #[cfg(not(feature = "cmd_alias"))]
57    let cmd = "previous-layout";
58    #[cfg(feature = "cmd_alias")]
59    let cmd = "prevl";
60
61    let mut s = Vec::new();
62    s.push(cmd);
63    #[cfg(feature = "tmux_1_3")]
64    s.extend_from_slice(&["-t", "1"]);
65    let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
66
67    let previous_layout = previous_layout.build().to_vec();
68
69    assert_eq!(previous_layout, s);
70}