tmux_interface/commands/clients_and_sessions/
detach_client.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type Detach<'a> = DetachClient<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
35pub struct DetachClient<'a> {
36 #[cfg(feature = "tmux_2_2")]
38 pub all: bool,
39
40 #[cfg(feature = "tmux_1_5")]
42 pub parent_sighup: bool,
43
44 #[cfg(feature = "tmux_2_4")]
46 pub shell_command: Option<Cow<'a, str>>,
47
48 #[cfg(feature = "tmux_1_5")]
50 pub target_session: Option<Cow<'a, str>>,
51
52 #[cfg(feature = "tmux_0_8")]
54 pub target_client: Option<Cow<'a, str>>,
55}
56
57impl<'a> DetachClient<'a> {
58 pub fn new() -> Self {
59 Default::default()
60 }
61
62 #[cfg(feature = "tmux_2_2")]
64 pub fn all(mut self) -> Self {
65 self.all = true;
66 self
67 }
68
69 #[cfg(feature = "tmux_1_5")]
71 pub fn parent_sighup(mut self) -> Self {
72 self.parent_sighup = true;
73 self
74 }
75
76 #[cfg(feature = "tmux_2_4")]
78 pub fn shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
79 self.shell_command = Some(shell_command.into());
80 self
81 }
82
83 #[cfg(feature = "tmux_1_5")]
85 pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
86 self.target_session = Some(target_session.into());
87 self
88 }
89
90 #[cfg(feature = "tmux_0_8")]
92 pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
93 self.target_client = Some(target_client.into());
94 self
95 }
96
97 pub fn build(self) -> TmuxCommand<'a> {
98 let mut cmd = TmuxCommand::new();
99
100 cmd.name(DETACH_CLIENT);
101
102 #[cfg(feature = "tmux_2_2")]
104 if self.all {
105 cmd.push_flag(A_LOWERCASE_KEY);
106 }
107
108 #[cfg(feature = "tmux_1_5")]
110 if self.parent_sighup {
111 cmd.push_flag(P_UPPERCASE_KEY);
112 }
113
114 #[cfg(feature = "tmux_2_4")]
116 if let Some(shell_command) = self.shell_command {
117 cmd.push_option(E_UPPERCASE_KEY, shell_command);
118 }
119
120 #[cfg(feature = "tmux_1_5")]
122 if let Some(target_session) = self.target_session {
123 cmd.push_option(S_LOWERCASE_KEY, target_session);
124 }
125
126 #[cfg(feature = "tmux_0_8")]
128 if let Some(target_client) = self.target_client {
129 cmd.push_option(T_LOWERCASE_KEY, target_client);
130 }
131
132 cmd
133 }
134}