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
122
123
124
125
126
127
128
129
130
131
132
133
134
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Detach<'a> = DetachClient<'a>;
/// Structure for detaching the current client
///
/// # Manual
///
/// tmux ^2.4:
/// ```text
/// detach-client [-aP] [-E shell-command] [-s target-session] [-t target-client]
/// (alias: detach)
/// ```
///
/// tmux ^2.2:
/// ```text
/// detach-client [-aP] [-s target-session] [-t target-client]
/// (alias: detach)
/// ```
///
/// tmux ^1.5:
/// ```text
/// detach-client [-P] [-s target-session] [-t target-client]
/// (alias: detach)
/// ```
///
/// tmux ^0.8:
/// ```text
/// detach-client [-t target-client]
/// (alias: detach)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct DetachClient<'a> {
/// `[-a]` - kill all but the client client given with `-t`
#[cfg(feature = "tmux_2_2")]
pub all: bool,
/// `[-P]` - send SIGHUP to the parent process of the client, typically causing it to exit
#[cfg(feature = "tmux_1_5")]
pub parent_sighup: bool,
/// `[-E shell-command]` - run shell-command to replace the client
#[cfg(feature = "tmux_2_4")]
pub shell_command: Option<Cow<'a, str>>,
/// `[-s target-session]` - specify the session, all clients currently attached
#[cfg(feature = "tmux_1_5")]
pub target_session: Option<Cow<'a, str>>,
/// `[-t target-client]` - specify the client
#[cfg(feature = "tmux_0_8")]
pub target_client: Option<Cow<'a, str>>,
}
impl<'a> DetachClient<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-a]` - kill all but the client client given with `-t`
#[cfg(feature = "tmux_2_2")]
pub fn all(mut self) -> Self {
self.all = true;
self
}
/// `[-P]` - send SIGHUP to the parent process of the client, typically causing it to exit
#[cfg(feature = "tmux_1_5")]
pub fn parent_sighup(mut self) -> Self {
self.parent_sighup = true;
self
}
/// `[-E shell-command]` - run shell-command to replace the client
#[cfg(feature = "tmux_2_4")]
pub fn shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
self.shell_command = Some(shell_command.into());
self
}
/// `[-s target-session]` - specify the session, all clients currently attached
#[cfg(feature = "tmux_1_5")]
pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
self.target_session = Some(target_session.into());
self
}
/// `[-t target-client]` - specify the client
#[cfg(feature = "tmux_0_8")]
pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
self.target_client = Some(target_client.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(DETACH_CLIENT);
// `[-a]` - kill all but the client client given with `-t`
#[cfg(feature = "tmux_2_2")]
if self.all {
cmd.push_flag(A_LOWERCASE_KEY);
}
// `[-P]` - send SIGHUP to the parent process of the client, typically causing it to exit
#[cfg(feature = "tmux_1_5")]
if self.parent_sighup {
cmd.push_flag(P_UPPERCASE_KEY);
}
// `[-E shell-command]` - run shell-command to replace the client
#[cfg(feature = "tmux_2_4")]
if let Some(shell_command) = self.shell_command {
cmd.push_option(E_UPPERCASE_KEY, shell_command);
}
// `[-s target-session]` - specify the session, all clients currently attached
#[cfg(feature = "tmux_1_5")]
if let Some(target_session) = self.target_session {
cmd.push_option(S_LOWERCASE_KEY, target_session);
}
// `[-t target-client]` - specify the client
#[cfg(feature = "tmux_0_8")]
if let Some(target_client) = self.target_client {
cmd.push_option(T_LOWERCASE_KEY, target_client);
}
cmd
}
}