#[macro_export]
macro_rules! send_keys {
(@cmd ($cmd:expr) -F, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.expand_formats()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -H, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.hex()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -K, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.client()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -l, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.disable_lookup()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -M, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.mouse_event()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -R, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.copy_mode()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -X, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.reset()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -N $repeat_count:expr, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.repeat_count($repeat_count)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -c $target_client:expr, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.target_client($target_client)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $target:expr, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
#[cfg(feature = "tmux_2_4")]
{
$cmd.target_pane($target)
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
{
$cmd.target_window($target)
}
}) $($tail)*)
}};
(@cmd ($cmd:expr) $key:expr, $($tail:tt)*) => {{
$crate::send_keys!(@cmd ({
$cmd.key($key)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::SendKeys::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::send_keys!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::send_keys!(@cmd ({ $crate::SendKeys::new() }) $($tail)*,)
}};
}
#[test]
fn send_keys_macro() {
use std::borrow::Cow;
let send_keys = send_keys!();
#[cfg(feature = "tmux_3_1")]
let send_keys = send_keys!((send_keys), -F);
#[cfg(feature = "tmux_3_0a")]
let send_keys = send_keys!((send_keys), -H);
#[cfg(feature = "tmux_3_4")]
let send_keys = send_keys!((send_keys), -K);
#[cfg(feature = "tmux_1_7")]
let send_keys = send_keys!((send_keys), -l);
#[cfg(feature = "tmux_2_1")]
let send_keys = send_keys!((send_keys), -M);
#[cfg(feature = "tmux_1_7")]
let send_keys = send_keys!((send_keys), -R);
#[cfg(feature = "tmux_2_4")]
let send_keys = send_keys!((send_keys), -X);
#[cfg(feature = "tmux_2_4")]
let send_keys = send_keys!((send_keys), -N 1);
#[cfg(feature = "tmux_3_4")]
let send_keys = send_keys!((send_keys), -c "2");
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
let send_keys = send_keys!((send_keys), -t "3");
#[cfg(feature = "tmux_2_4")]
let send_keys = send_keys!((send_keys), -t "4");
#[cfg(feature = "tmux_0_8")]
let send_keys = send_keys!((send_keys), "5");
#[cfg(feature = "tmux_0_8")]
let send_keys = send_keys!((send_keys), "6");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "send-keys";
#[cfg(feature = "cmd_alias")]
let cmd = "send";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_3_1")]
s.push("-F");
#[cfg(feature = "tmux_3_0a")]
s.push("-H");
#[cfg(feature = "tmux_3_4")]
s.push("-K");
#[cfg(feature = "tmux_1_7")]
s.push("-l");
#[cfg(feature = "tmux_2_1")]
s.push("-M");
#[cfg(feature = "tmux_1_7")]
s.push("-R");
#[cfg(feature = "tmux_2_4")]
s.push("-X");
#[cfg(feature = "tmux_2_4")]
s.extend_from_slice(&["-N", "1"]);
#[cfg(feature = "tmux_3_4")]
s.extend_from_slice(&["-c", "2"]);
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
s.extend_from_slice(&["-t", "3"]);
#[cfg(feature = "tmux_2_4")]
s.extend_from_slice(&["-t", "4"]);
#[cfg(feature = "tmux_0_8")]
s.push("5");
#[cfg(feature = "tmux_0_8")]
s.push("6");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let send_keys = send_keys.build().to_vec();
assert_eq!(send_keys, s);
}