tmux_interface/commands/windows_and_panes/
last_pane_macro.rs1#[macro_export]
24macro_rules! last_pane {
25 (@cmd ($cmd:expr) -d, $($tail:tt)*) => {{
27 $crate::last_pane!(@cmd ({
28 $cmd.disable()
29 }) $($tail)*)
30 }};
31 (@cmd ($cmd:expr) -e, $($tail:tt)*) => {{
33 $crate::last_pane!(@cmd ({
34 $cmd.enable()
35 }) $($tail)*)
36 }};
37 (@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
39 $crate::last_pane!(@cmd ({
40 $cmd.keep_zoomed()
41 }) $($tail)*)
42 }};
43 (@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)) => {{
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 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}