1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
// XXX: better return type
/// List panes on the server
///
/// # Manual
///
/// tmux ^1.6:
/// ```text
/// list-panes [-as] [-F format] [-t target]
/// (alias: lsp)
/// ```
///
/// tmux ^1.5:
/// ```text
/// list-panes [-as] [-t target]
/// (alias: lsp)
/// ```
///
/// tmux ^0.8:
/// ```text
/// list-panes [-t target]
/// (alias: lsp)
/// ```
#[macro_export]
macro_rules! list_panes {
// `[-a]`
(@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
$crate::list_panes!(@cmd ({
$cmd.all()
}) $($tail)*)
}};
// `[-s]`
(@cmd ($cmd:expr) -s, $($tail:tt)*) => {{
$crate::list_panes!(@cmd ({
$cmd.session()
}) $($tail)*)
}};
// `[-F format]`
(@cmd ($cmd:expr) -F $format:expr, $($tail:tt)*) => {{
$crate::list_panes!(@cmd ({
$cmd.format($format)
}) $($tail)*)
}};
// `[-t target]`
(@cmd ($cmd:expr) -t $target:expr, $($tail:tt)*) => {{
$crate::list_panes!(@cmd ({
$cmd.target($target)
}) $($tail)*)
}};
//(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
//::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
//}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::ListPanes::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::list_panes!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::list_panes!(@cmd ({ $crate::ListPanes::new() }) $($tail)*,)
}};
}
#[test]
fn list_panes_macro() {
use std::borrow::Cow;
// List panes on the server
//
// # Manual
//
// tmux ^1.6:
// ```text
// list-panes [-as] [-F format] [-t target]
// (alias: lsp)
// ```
//
// tmux ^1.5:
// ```text
// list-panes [-as] [-t target]
// (alias: lsp)
// ```
//
// tmux ^0.8:
// ```text
// list-panes [-t target]
// (alias: lsp)
// ```
let list_panes = list_panes!();
#[cfg(feature = "tmux_1_5")]
let list_panes = list_panes!((list_panes), -a);
#[cfg(feature = "tmux_1_5")]
let list_panes = list_panes!((list_panes), -s);
#[cfg(feature = "tmux_1_6")]
let list_panes = list_panes!((list_panes), -F "1");
#[cfg(feature = "tmux_0_8")]
let list_panes = list_panes!((list_panes), -t "2");
#[cfg(not(feature = "cmd_alias"))]
let cmd = "list-panes";
#[cfg(feature = "cmd_alias")]
let cmd = "lsp";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_1_5")]
s.push("-a");
#[cfg(feature = "tmux_1_5")]
s.push("-s");
#[cfg(feature = "tmux_1_6")]
s.extend_from_slice(&["-F", "1"]);
#[cfg(feature = "tmux_0_8")]
s.extend_from_slice(&["-t", "2"]);
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let list_panes = list_panes.build().to_vec();
assert_eq!(list_panes, s);
}