tmux_interface/commands/windows_and_panes/
last_pane_macro.rs

1/// Select the last (previously selected) pane
2///
3/// # Manual
4///
5/// tmux ^3.1:
6/// ```text
7/// last-pane [-deZ] [-t target-window]
8/// (alias: lastp)
9/// ```
10///
11/// tmux ^2.0:
12/// ```text
13/// last-pane [-de] [-t target-window]
14/// (alias: lastp)
15/// ```
16///
17/// tmux ^1.4:
18/// ```text
19/// last-pane [-t target-window]
20/// (alias: lastp)
21/// ```
22// FIXME: versions and function parameters
23#[macro_export]
24macro_rules! last_pane {
25    // `[-d]`
26    (@cmd ($cmd:expr) -d, $($tail:tt)*) => {{
27        $crate::last_pane!(@cmd ({
28            $cmd.disable()
29        }) $($tail)*)
30    }};
31    // `[-e]`
32    (@cmd ($cmd:expr) -e, $($tail:tt)*) => {{
33        $crate::last_pane!(@cmd ({
34            $cmd.enable()
35        }) $($tail)*)
36    }};
37    // `[-Z]`
38    (@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
39        $crate::last_pane!(@cmd ({
40            $cmd.keep_zoomed()
41        }) $($tail)*)
42    }};
43    // `[-t target-window]`
44    (@cmd ($cmd:expr) -t $target_window:expr, $($tail:tt)*) => {{
45        $crate::last_pane!(@cmd ({
46            $cmd.target_window($target_window)
47        }) $($tail)*)
48    }};
49    //(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
50        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
51    //}};
52    (@cmd ($cmd:expr)) => {{
53        $cmd
54    }};
55    () => {{
56        $crate::LastPane::new()
57    }};
58    (($cmd:expr), $($tail:tt)*) => {{
59        $crate::last_pane!(@cmd ($cmd) $($tail)*,)
60    }};
61    ($($tail:tt)*) => {{
62        $crate::last_pane!(@cmd ({ $crate::LastPane::new() }) $($tail)*,)
63    }};
64}
65
66#[test]
67fn last_pane_macro() {
68    use crate::TargetWindow;
69    use std::borrow::Cow;
70
71    // Select the last (previously selected) pane
72    //
73    // # Manual
74    //
75    // tmux ^3.1:
76    // ```text
77    // last-pane [-deZ] [-t target-window]
78    // (alias: lastp)
79    // ```
80    //
81    // tmux ^2.0:
82    // ```text
83    // last-pane [-de] [-t target-window]
84    // (alias: lastp)
85    // ```
86    //
87    // tmux ^1.4:
88    // ```text
89    // last-pane [-t target-window]
90    // (alias: lastp)
91    // ```
92    let target_window = TargetWindow::Raw("1").to_string();
93
94    let last_pane = last_pane!();
95    #[cfg(feature = "tmux_2_0")]
96    let last_pane = last_pane!((last_pane), -d);
97    #[cfg(feature = "tmux_2_0")]
98    let last_pane = last_pane!((last_pane), -e);
99    #[cfg(feature = "tmux_3_1")]
100    let last_pane = last_pane!((last_pane), -Z);
101    #[cfg(feature = "tmux_1_4")]
102    let last_pane = last_pane!((last_pane), -t & target_window);
103
104    #[cfg(not(feature = "cmd_alias"))]
105    let cmd = "last-pane";
106    #[cfg(feature = "cmd_alias")]
107    let cmd = "lastp";
108
109    let mut s = Vec::new();
110    s.push(cmd);
111    #[cfg(feature = "tmux_2_0")]
112    s.push("-d");
113    #[cfg(feature = "tmux_2_0")]
114    s.push("-e");
115    #[cfg(feature = "tmux_3_1")]
116    s.push("-Z");
117    #[cfg(feature = "tmux_1_4")]
118    s.extend_from_slice(&["-t", "1"]);
119    let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
120
121    let last_pane = last_pane.build().to_vec();
122
123    assert_eq!(last_pane, s);
124}