tmux_interface/commands/clients_and_sessions/
detach_client_macro.rs1#[macro_export]
27macro_rules! detach_client {
28 (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
30 $crate::detach_client!(@cmd ({
31 $cmd.all()
32 }) $($tail)*)
33 }};
34 (@cmd ($cmd:expr) -P, $($tail:tt)*) => {{
36 $crate::detach_client!(@cmd ({
37 $cmd.parent_sighup()
38 }) $($tail)*)
39 }};
40 (@cmd ($cmd:expr) -E $shell_command:expr, $($tail:tt)*) => {{
42 $crate::detach_client!(@cmd ({
43 $cmd.shell_command($shell_command)
44 }) $($tail)*)
45 }};
46 (@cmd ($cmd:expr) -s $target_session:expr, $($tail:tt)*) => {{
48 $crate::detach_client!(@cmd ({
49 $cmd.target_session($target_session)
50 }) $($tail)*)
51 }};
52 (@cmd ($cmd:expr) -t $target_client:expr, $($tail:tt)*) => {{
54 $crate::detach_client!(@cmd ({
55 $cmd.target_client($target_client)
56 }) $($tail)*)
57 }};
58 (@cmd ($cmd:expr)) => {{
62 $cmd
63 }};
64 () => {{
65 $crate::DetachClient::new()
66 }};
67 (($cmd:expr), $($tail:tt)*) => {{
68 $crate::detach_client!(@cmd ($cmd) $($tail)*,)
69 }};
70 ($($tail:tt)*) => {{
71 $crate::detach_client!(@cmd ({ $crate::DetachClient::new() }) $($tail)*,)
72 }};
73}
74
75#[test]
76fn detach_client_macro() {
77 use crate::detach_client;
78 use crate::TargetSession;
79 use std::borrow::Cow;
80
81 let target_session = TargetSession::Raw("2").to_string();
109
110 let detach_client = detach_client!();
111 #[cfg(feature = "tmux_2_2")]
112 let detach_client = detach_client!((detach_client), -a);
113 #[cfg(feature = "tmux_1_5")]
114 let detach_client = detach_client!((detach_client), -P);
115 #[cfg(feature = "tmux_2_4")]
116 let detach_client = detach_client!((detach_client), -E "1");
117 #[cfg(feature = "tmux_1_5")]
118 let detach_client = detach_client!((detach_client), -s & target_session);
119 #[cfg(feature = "tmux_0_8")]
120 let detach_client = detach_client!((detach_client), -t "3");
121
122 #[cfg(not(feature = "cmd_alias"))]
123 let cmd = "detach-client";
124 #[cfg(feature = "cmd_alias")]
125 let cmd = "detach";
126
127 let mut s = Vec::new();
128 s.push(cmd);
129 #[cfg(feature = "tmux_2_2")]
130 s.push("-a");
131 #[cfg(feature = "tmux_1_5")]
132 s.push("-P");
133 #[cfg(feature = "tmux_2_4")]
134 s.extend_from_slice(&["-E", "1"]);
135 #[cfg(feature = "tmux_1_5")]
136 s.extend_from_slice(&["-s", "2"]);
137 #[cfg(feature = "tmux_0_8")]
138 s.extend_from_slice(&["-t", "3"]);
139 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
140
141 let detach_client = detach_client.build().to_vec();
142
143 assert_eq!(detach_client, s);
144}