#[macro_export]
macro_rules! swap_pane {
(@cmd ($cmd:expr) -d, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.detached()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -D, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.previous_pane()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -U, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.next_pane()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -Z, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.keep_zoomed()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -p $src_index:expr, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.src_index($src_index)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -s $src_pane:expr, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.src_pane($src_pane)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -q $dst_index:expr, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
$cmd.dst_index($dst_index)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target:expr, $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
{
$cmd.target_window($target)
}
#[cfg(feature = "tmux_1_5")]
{
$cmd.dst_pane($target)
}
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::SwapPane::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::swap_pane!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::swap_pane!(@cmd ({ $crate::SwapPane::new() }) $($tail)*,)
}};
}
#[test]
fn swap_pane_macro() {
use std::borrow::Cow;
let swap_pane = swap_pane!();
#[cfg(feature = "tmux_0_8")]
let swap_pane = swap_pane!((swap_pane), -d);
#[cfg(feature = "tmux_0_8")]
let swap_pane = swap_pane!((swap_pane), -D);
#[cfg(feature = "tmux_0_8")]
let swap_pane = swap_pane!((swap_pane), -U);
#[cfg(feature = "tmux_3_1")]
let swap_pane = swap_pane!((swap_pane), -Z);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
let swap_pane = swap_pane!((swap_pane), -p "1");
#[cfg(feature = "tmux_1_5")]
let swap_pane = swap_pane!((swap_pane), -s "2");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
let swap_pane = swap_pane!((swap_pane), -q "3");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
let swap_pane = swap_pane!((swap_pane), -t "4");
#[cfg(feature = "tmux_1_5")]
let swap_pane = swap_pane!((swap_pane), -t "5");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "swap-pane";
#[cfg(feature = "cmd_alias")]
let cmd = "swapp";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_0_8")]
s.push("-d");
#[cfg(feature = "tmux_0_8")]
s.push("-D");
#[cfg(feature = "tmux_0_8")]
s.push("-U");
#[cfg(feature = "tmux_3_1")]
s.push("-Z");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
s.extend_from_slice(&["-p", "1"]);
#[cfg(feature = "tmux_1_5")]
s.extend_from_slice(&["-s", "2"]);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
s.extend_from_slice(&["-q", "3"]);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
s.extend_from_slice(&["-t", "4"]);
#[cfg(feature = "tmux_1_5")]
s.extend_from_slice(&["-t", "5"]);
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let swap_pane = swap_pane.build().to_vec();
assert_eq!(swap_pane, s);
}