#[macro_export]
macro_rules! unbind_key {
(@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.all()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -c, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.command_mode()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -n, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.root()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -q, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.quiet()
}) $($tail)*)
}};
(@cmd ($cmd:expr) -t $table:expr, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
{
$cmd.mode_table($table)
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
{
$cmd.key_table($table)
}
}) $($tail)*)
}};
(@cmd ($cmd:expr) -T $key_table:expr, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.key_table($key_table)
}) $($tail)*)
}};
(@cmd ($cmd:expr) $key:expr, $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({
$cmd.key($key)
}) $($tail)*)
}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::UnbindKey::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::unbind_key!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::unbind_key!(@cmd ({ $crate::UnbindKey::new() }) $($tail)*,)
}};
}
#[test]
fn unbind_key_macro() {
use std::borrow::Cow;
let unbind_key = unbind_key!();
#[cfg(feature = "tmux_1_5")]
let unbind_key = unbind_key!((unbind_key), -a);
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_4")))]
let unbind_key = unbind_key!((unbind_key), -c);
#[cfg(feature = "tmux_1_5")]
let unbind_key = unbind_key!((unbind_key), -n);
#[cfg(feature = "tmux_3_2")]
let unbind_key = unbind_key!((unbind_key), -q);
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
let unbind_key = unbind_key!((unbind_key), -t "1");
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
let unbind_key = unbind_key!((unbind_key), -t "2");
#[cfg(feature = "tmux_2_1")]
let unbind_key = unbind_key!((unbind_key), -T "3");
#[cfg(feature = "tmux_0_8")]
let unbind_key = unbind_key!((unbind_key), "4");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "unbind-key";
#[cfg(feature = "cmd_alias")]
let cmd = "unbind";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_1_5")]
s.push("-a");
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_4")))]
s.push("-c");
#[cfg(feature = "tmux_1_5")]
s.push("-n");
#[cfg(feature = "tmux_3_2")]
s.push("-q");
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
s.extend_from_slice(&["-t", "1"]);
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
s.extend_from_slice(&["-t", "2"]);
#[cfg(feature = "tmux_2_1")]
s.extend_from_slice(&["-T", "3"]);
#[cfg(feature = "tmux_0_8")]
s.push("4");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let unbind_key = unbind_key.build().to_vec();
assert_eq!(unbind_key, s);
}