#[macro_export]
macro_rules! bind_key {
(@cmd ($cmd:expr) -n, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.root()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -r, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.repeat()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -N $note:expr, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.note($note)
}) $($tail)*)
}};
(@cmd ($cmd:expr) -T $key_table:expr, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.key_table($key_table)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $arguments:expr, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.arguments($arguments)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $key:expr, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.key($key)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $command:expr, $($tail:tt)*) => {{
$crate::bind_key!(@cmd ({
$cmd.command($command)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::BindKey::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::bind_key!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::bind_key!(@cmd ({ $crate::BindKey::new() }) $($tail)*,)
}};
}
#[test]
fn bind_key_macro() {
use std::borrow::Cow;
let bind_key = bind_key!();
#[cfg(feature = "tmux_1_0")]
let bind_key = bind_key!((bind_key), -n);
#[cfg(feature = "tmux_0_8")]
let bind_key = bind_key!((bind_key), -r);
#[cfg(feature = "tmux_3_1")]
let bind_key = bind_key!((bind_key), -N "1");
#[cfg(feature = "tmux_2_1")]
let bind_key = bind_key!((bind_key), -T "2");
#[cfg(feature = "tmux_0_8")]
let bind_key = bind_key!((bind_key), "3");
#[cfg(feature = "tmux_0_8")]
let bind_key = bind_key!((bind_key), "4");
#[cfg(feature = "tmux_0_8")]
let bind_key = bind_key!((bind_key), "5");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "bind-key";
#[cfg(feature = "cmd_alias")]
let cmd = "bind";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_1_0")]
s.push("-n");
#[cfg(feature = "tmux_0_8")]
s.push("-r");
#[cfg(feature = "tmux_3_1")]
s.extend_from_slice(&["-N", "1"]);
#[cfg(feature = "tmux_2_1")]
s.extend_from_slice(&["-T", "2"]);
#[cfg(feature = "tmux_0_8")]
s.push("3");
#[cfg(feature = "tmux_0_8")]
s.push("4");
#[cfg(feature = "tmux_0_8")]
s.push("5");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let bind_key = bind_key.build().to_vec();
assert_eq!(bind_key, s);
}