tmux_interface/commands/options/
set_option.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type Set<'a> = SetOption<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
59pub struct SetOption<'a> {
60 #[cfg(feature = "tmux_1_0")]
62 pub append: bool,
63
64 #[cfg(feature = "tmux_2_6")]
66 pub format: bool,
67
68 #[cfg(feature = "tmux_0_8")]
70 pub global: bool,
71
72 #[cfg(feature = "tmux_1_8")]
74 pub not_overwrite: bool,
75
76 #[cfg(feature = "tmux_3_0")]
78 pub pane: bool,
79
80 #[cfg(feature = "tmux_1_7")]
82 pub quiet: bool,
83
84 #[cfg(feature = "tmux_1_2")]
86 pub server: bool,
87
88 #[cfg(feature = "tmux_0_8")]
90 pub unset: bool,
91
92 #[cfg(feature = "tmux_3_2")]
94 pub unset_on_all: bool,
95
96 #[cfg(feature = "tmux_1_2")]
98 pub window: bool,
99
100 #[cfg(feature = "tmux_3_0")]
102 pub target_pane: Option<Cow<'a, str>>,
103
104 #[cfg(all(feature = "tmux_1_2", not(feature = "tmux_3_0")))]
106 pub target: Option<Cow<'a, str>>,
107
108 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_2")))]
110 pub target_session: Option<Cow<'a, str>>,
111
112 pub option: Option<Cow<'a, str>>,
115
116 pub value: Option<Cow<'a, str>>,
118}
119
120impl<'a> SetOption<'a> {
121 pub fn new() -> Self {
122 Default::default()
123 }
124
125 #[cfg(feature = "tmux_1_0")]
127 pub fn append(mut self) -> Self {
128 self.append = true;
129 self
130 }
131
132 #[cfg(feature = "tmux_2_6")]
134 pub fn format(mut self) -> Self {
135 self.format = true;
136 self
137 }
138
139 #[cfg(feature = "tmux_0_8")]
141 pub fn global(mut self) -> Self {
142 self.global = true;
143 self
144 }
145
146 #[cfg(feature = "tmux_1_8")]
148 pub fn not_overwrite(mut self) -> Self {
149 self.not_overwrite = true;
150 self
151 }
152
153 #[cfg(feature = "tmux_3_0")]
155 pub fn pane(mut self) -> Self {
156 self.pane = true;
157 self
158 }
159
160 #[cfg(feature = "tmux_1_7")]
162 pub fn quiet(mut self) -> Self {
163 self.quiet = true;
164 self
165 }
166
167 #[cfg(feature = "tmux_1_2")]
169 pub fn server(mut self) -> Self {
170 self.server = true;
171 self
172 }
173
174 #[cfg(feature = "tmux_0_8")]
176 pub fn unset(mut self) -> Self {
177 self.unset = true;
178 self
179 }
180
181 #[cfg(feature = "tmux_3_2")]
183 pub fn unset_on_all(mut self) -> Self {
184 self.unset_on_all = true;
185 self
186 }
187
188 #[cfg(feature = "tmux_1_2")]
190 pub fn window(mut self) -> Self {
191 self.window = true;
192 self
193 }
194
195 #[cfg(feature = "tmux_3_0")]
197 pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
198 self.target_pane = Some(target_pane.into());
199 self
200 }
201
202 #[cfg(all(feature = "tmux_1_2", not(feature = "tmux_3_0")))]
204 pub fn target<S: Into<Cow<'a, str>>>(mut self, target: S) -> Self {
205 self.target = Some(target.into());
206 self
207 }
208
209 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_2")))]
211 pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
212 self.target_session = Some(target_session.into());
213 self
214 }
215
216 pub fn option<S: Into<Cow<'a, str>>>(mut self, option: S) -> Self {
220 self.option = Some(option.into());
221 self
222 }
223
224 pub fn value<S: Into<Cow<'a, str>>>(mut self, value: S) -> Self {
226 self.value = Some(value.into());
227 self
228 }
229
230 pub fn build(self) -> TmuxCommand<'a> {
231 let mut cmd = TmuxCommand::new();
232
233 cmd.name(SET_OPTION);
234
235 #[cfg(feature = "tmux_1_0")]
237 if self.append {
238 cmd.push_flag(A_LOWERCASE_KEY);
239 }
240
241 #[cfg(feature = "tmux_2_6")]
243 if self.format {
244 cmd.push_flag(F_UPPERCASE_KEY);
245 }
246
247 #[cfg(feature = "tmux_0_8")]
249 if self.global {
250 cmd.push_flag(G_LOWERCASE_KEY);
251 }
252
253 #[cfg(feature = "tmux_1_8")]
255 if self.not_overwrite {
256 cmd.push_flag(O_LOWERCASE_KEY);
257 }
258
259 #[cfg(feature = "tmux_3_0")]
261 if self.pane {
262 cmd.push_flag(P_LOWERCASE_KEY);
263 }
264
265 #[cfg(feature = "tmux_1_7")]
267 if self.quiet {
268 cmd.push_flag(Q_LOWERCASE_KEY);
269 }
270
271 #[cfg(feature = "tmux_1_2")]
273 if self.server {
274 cmd.push_flag(S_LOWERCASE_KEY);
275 }
276
277 #[cfg(feature = "tmux_0_8")]
279 if self.unset {
280 cmd.push_flag(U_LOWERCASE_KEY);
281 }
282
283 #[cfg(feature = "tmux_3_2")]
285 if self.unset_on_all {
286 cmd.push_flag(U_UPPERCASE_KEY);
287 }
288
289 #[cfg(feature = "tmux_1_2")]
291 if self.window {
292 cmd.push_flag(W_LOWERCASE_KEY);
293 }
294
295 #[cfg(feature = "tmux_3_0")]
297 if let Some(target_pane) = self.target_pane {
298 cmd.push_option(T_LOWERCASE_KEY, target_pane);
299 }
300
301 #[cfg(all(feature = "tmux_1_2", not(feature = "tmux_3_0")))]
303 if let Some(target) = self.target {
304 cmd.push_option(T_LOWERCASE_KEY, target);
305 }
306
307 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_2")))]
309 if let Some(target_session) = self.target_session {
310 cmd.push_option(T_LOWERCASE_KEY, target_session);
311 }
312
313 if let Some(option) = self.option {
317 cmd.push_param(option);
318 }
319
320 if let Some(value) = self.value {
322 cmd.push_param(value);
323 }
324
325 cmd
326 }
327}