#[macro_export]
macro_rules! pipe_pane {
(@cmd ($cmd:expr) -I, $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({
$cmd.stdout()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -O, $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({
$cmd.stdin()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -o, $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({
$cmd.open()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_pane:expr, $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({
$cmd.target_pane($target_pane)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $shell_command:expr, $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({
$cmd.shell_command($shell_command)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::PipePane::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::pipe_pane!(@cmd ({ $crate::PipePane::new() }) $($tail)*,)
}};
}
#[test]
fn pipe_pane_macro() {
use std::borrow::Cow;
let pipe_pane = pipe_pane!();
#[cfg(feature = "tmux_2_7")]
let pipe_pane = pipe_pane!((pipe_pane), -I);
#[cfg(feature = "tmux_2_7")]
let pipe_pane = pipe_pane!((pipe_pane), -O);
#[cfg(feature = "tmux_1_5")]
let pipe_pane = pipe_pane!((pipe_pane), -o);
#[cfg(feature = "tmux_1_5")]
let pipe_pane = pipe_pane!((pipe_pane), -t "1");
#[cfg(feature = "tmux_1_5")]
let pipe_pane = pipe_pane!((pipe_pane), "2");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "pipe-pane";
#[cfg(feature = "cmd_alias")]
let cmd = "pipep";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_2_7")]
s.push("-I");
#[cfg(feature = "tmux_2_7")]
s.push("-O");
#[cfg(feature = "tmux_1_5")]
s.push("-o");
#[cfg(feature = "tmux_1_5")]
s.extend_from_slice(&["-t", "1"]);
#[cfg(feature = "tmux_1_5")]
s.push("2");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let pipe_pane = pipe_pane.build().to_vec();
assert_eq!(pipe_pane, s);
}