#[macro_export]
macro_rules! set_hook {
(@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.append()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -g, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.global()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -p, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.pane()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -R, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.run()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -u, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.unset()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -w, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.window()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.target_session($target_session)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $hook_name:expr, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.hook_name($hook_name)
}) $($tail)*)
}};
(@cmd ($cmd:expr) --command $command:expr, $($tail:tt)*) => {{
$crate::set_hook!(@cmd ({
$cmd.command($command)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::SetHook::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::set_hook!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::set_hook!(@cmd ({ $crate::SetHook::new() }) $($tail)*,)
}};
}
#[test]
fn set_hook_macro() {
use std::borrow::Cow;
let set_hook = set_hook!();
#[cfg(feature = "tmux_3_0")]
let set_hook = set_hook!((set_hook), -a);
#[cfg(feature = "tmux_2_2")]
let set_hook = set_hook!((set_hook), -g);
#[cfg(feature = "tmux_3_2")]
let set_hook = set_hook!((set_hook), -p);
#[cfg(feature = "tmux_2_8")]
let set_hook = set_hook!((set_hook), -R);
#[cfg(feature = "tmux_2_4")]
let set_hook = set_hook!((set_hook), -u);
#[cfg(feature = "tmux_3_2")]
let set_hook = set_hook!((set_hook), -w);
#[cfg(feature = "tmux_2_2")]
let set_hook = set_hook!((set_hook), -t "1");
#[cfg(feature = "tmux_2_2")]
let set_hook = set_hook!((set_hook), "2");
#[cfg(feature = "tmux_2_2")]
let set_hook = set_hook!((set_hook), --command "3");
let cmd = "set-hook";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_3_0")]
s.push("-a");
#[cfg(feature = "tmux_2_2")]
s.push("-g");
#[cfg(feature = "tmux_3_2")]
s.push("-p");
#[cfg(feature = "tmux_2_8")]
s.push("-R");
#[cfg(feature = "tmux_2_4")]
s.push("-u");
#[cfg(feature = "tmux_3_2")]
s.push("-w");
#[cfg(feature = "tmux_2_2")]
s.extend_from_slice(&["-t", "1"]);
#[cfg(feature = "tmux_2_2")]
s.push("2");
#[cfg(feature = "tmux_2_2")]
s.push("3");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let set_hook = set_hook.build().to_vec();
assert_eq!(set_hook, s);
}