tmux_interface/commands/hooks/
set_hook.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct SetHook<'a> {
30 #[cfg(feature = "tmux_3_0")]
32 pub append: bool,
33
34 #[cfg(feature = "tmux_2_2")]
36 pub global: bool,
37
38 #[cfg(feature = "tmux_2_8")]
40 pub run: bool,
41
42 #[cfg(feature = "tmux_2_4")]
44 pub unset: bool,
45
46 #[cfg(feature = "tmux_2_2")]
48 pub target_session: Option<Cow<'a, str>>,
49
50 #[cfg(feature = "tmux_2_2")]
52 pub hook_name: Option<Cow<'a, str>>,
53
54 #[cfg(feature = "tmux_2_2")]
56 pub command: Option<Cow<'a, str>>,
57}
58
59impl<'a> SetHook<'a> {
60 pub fn new() -> Self {
61 Default::default()
62 }
63
64 #[cfg(feature = "tmux_3_0")]
66 pub fn append(mut self) -> Self {
67 self.append = true;
68 self
69 }
70
71 #[cfg(feature = "tmux_2_2")]
73 pub fn global(mut self) -> Self {
74 self.global = true;
75 self
76 }
77
78 #[cfg(feature = "tmux_2_8")]
80 pub fn run(mut self) -> Self {
81 self.run = true;
82 self
83 }
84
85 #[cfg(feature = "tmux_2_4")]
87 pub fn unset(mut self) -> Self {
88 self.unset = true;
89 self
90 }
91
92 #[cfg(feature = "tmux_2_2")]
94 pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
95 self.target_session = Some(target_session.into());
96 self
97 }
98
99 #[cfg(feature = "tmux_2_2")]
101 pub fn hook_name<S: Into<Cow<'a, str>>>(mut self, hook_name: S) -> Self {
102 self.hook_name = Some(hook_name.into());
103 self
104 }
105
106 #[cfg(feature = "tmux_2_2")]
109 pub fn command<S: Into<Cow<'a, str>>>(mut self, command: S) -> Self {
110 self.command = Some(command.into());
111 self
112 }
113
114 pub fn build(self) -> TmuxCommand<'a> {
115 let mut cmd = TmuxCommand::new();
116
117 cmd.name(SET_HOOK);
118
119 #[cfg(feature = "tmux_3_0")]
121 if self.append {
122 cmd.push_flag(A_LOWERCASE_KEY);
123 }
124
125 #[cfg(feature = "tmux_2_2")]
127 if self.global {
128 cmd.push_flag(G_LOWERCASE_KEY);
129 }
130
131 #[cfg(feature = "tmux_2_8")]
133 if self.run {
134 cmd.push_flag(R_UPPERCASE_KEY);
135 }
136
137 #[cfg(feature = "tmux_2_4")]
139 if self.unset {
140 cmd.push_flag(U_LOWERCASE_KEY);
141 }
142
143 #[cfg(feature = "tmux_2_2")]
145 if let Some(target_session) = self.target_session {
146 cmd.push_option(T_LOWERCASE_KEY, target_session);
147 }
148
149 #[cfg(feature = "tmux_2_2")]
151 if let Some(hook_name) = self.hook_name {
152 cmd.push_param(hook_name);
153 }
154
155 #[cfg(feature = "tmux_2_2")]
157 if let Some(command) = self.command {
158 cmd.push_param(command);
159 }
160
161 cmd
162 }
163}