tmux_interface/commands/clients_and_sessions/
kill_session_macro.rs1#[macro_export]
20macro_rules! kill_session {
21 (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
22 $crate::kill_session!(@cmd ({
23 $cmd.all()
24 }) $($tail)*)
25 }};
26 (@cmd ($cmd:expr) -C, $($tail:tt)*) => {{
27 $crate::kill_session!(@cmd ({
28 $cmd.clear_alerts()
29 }) $($tail)*)
30 }};
31 (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
33 $crate::kill_session!(@cmd ({
34 $cmd.target_session($target_session)
35 }) $($tail)*)
36 }};
37 (@cmd ($cmd:expr)) => {{
41 $cmd
42 }};
43 () => {{
44 $crate::KillSession::new()
45 }};
46 (($cmd:expr), $($tail:tt)*) => {{
47 $crate::kill_session!(@cmd ($cmd) $($tail)*,)
48 }};
49 ($($tail:tt)*) => {{
50 $crate::kill_session!(@cmd ({ $crate::KillSession::new() }) $($tail)*,)
51 }};
52
53}
54
55#[test]
56fn kill_session_macro() {
57 use crate::TargetSession;
58 use std::borrow::Cow;
59
60 let target_session = TargetSession::Raw("1").to_string();
79
80 let kill_session = kill_session!();
81 #[cfg(feature = "tmux_2_2")]
82 let kill_session = kill_session!((kill_session), -a);
83 #[cfg(feature = "tmux_1_7")]
84 let kill_session = kill_session!((kill_session), -C);
85 #[cfg(feature = "tmux_0_8")]
86 let kill_session = kill_session!((kill_session), -t & target_session);
87
88 let cmd = "kill-session";
89
90 let mut s = Vec::new();
91 s.push(cmd);
92 #[cfg(feature = "tmux_2_2")]
93 s.push("-a");
94 #[cfg(feature = "tmux_1_7")]
95 s.push("-C");
96 #[cfg(feature = "tmux_0_8")]
97 s.extend_from_slice(&["-t", "1"]);
98 let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
99
100 let kill_session = kill_session.build().to_vec();
101
102 assert_eq!(kill_session, s);
103}