tmux_interface/commands/options/
show_options.rs

1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type Show<'a> = ShowOptions<'a>;
6
7/// Structure for showing options
8///
9/// # Manual
10///
11/// tmux ^3.0:
12/// ```text
13/// show-options [-AgHpqsvw] [-t target-pane] [option]
14/// (alias: show)
15/// ```
16///
17/// tmux ^1.8:
18/// ```text
19/// show-options [-gqsvw] [-t target-session | target-window] [option]
20/// (alias: show)
21/// ```
22///
23/// tmux ^1.7:
24/// ```text
25/// show-options [-gsw] [-t target-session | target-window] [option]
26/// (alias: show)
27/// ```
28///
29/// tmux ^1.2:
30/// ```text
31/// show-options [-gsw] [-t target-session | target-window]
32/// (alias: show)
33/// ```
34///
35/// tmux ^1.0:
36/// ```text
37/// show-options [-t target-session]
38/// (alias: show)
39/// ```
40///
41/// tmux ^0.8:
42/// ```text
43/// show-options [-t target-session] option value
44/// (alias: show)
45/// ```
46// XXX: better result type?
47#[derive(Debug, Default, Clone)]
48pub struct ShowOptions<'a> {
49    /// `[-A]` - includes options inherited from a parent set of options
50    #[cfg(feature = "tmux_3_0")]
51    pub include_inherited: bool,
52
53    /// `[-g]` - global session or window options are listed
54    #[cfg(feature = "tmux_1_2")]
55    pub global: bool,
56
57    /// `[-H]` - includes hooks (omitted by default)
58    #[cfg(feature = "tmux_3_0")]
59    pub hooks: bool,
60
61    /// `[-p]` - show window options
62    #[cfg(feature = "tmux_3_0")]
63    pub pane: bool,
64
65    /// `[-q]` - no error will be returned if `option` is unset
66    #[cfg(feature = "tmux_1_8")]
67    pub quiet: bool,
68
69    /// `[-s]` - show the server options
70    #[cfg(feature = "tmux_1_2")]
71    pub server: bool,
72
73    /// `[-v]` - shows only the option value
74    #[cfg(feature = "tmux_1_8")]
75    pub value: bool,
76
77    /// `[-w]` - show the window options
78    #[cfg(feature = "tmux_1_2")]
79    pub window: bool,
80
81    /// `[-t target-pane]` - target session or window name
82    //#[cfg(feature = "tmux_X_X")]
83    pub target: Option<Cow<'a, str>>,
84
85    /// `[option]` - specify option name
86    #[cfg(feature = "tmux_1_7")]
87    pub option: Option<Cow<'a, str>>,
88}
89
90impl<'a> ShowOptions<'a> {
91    pub fn new() -> Self {
92        Default::default()
93    }
94
95    /// `[-A]` - includes options inherited from a parent set of options
96    #[cfg(feature = "tmux_3_0")]
97    pub fn include_inherited(mut self) -> Self {
98        self.include_inherited = true;
99        self
100    }
101
102    /// `[-g]` - global session or window options are listed
103    #[cfg(feature = "tmux_1_2")]
104    pub fn global(mut self) -> Self {
105        self.global = true;
106        self
107    }
108
109    /// `[-H]` - includes hooks (omitted by default)
110    #[cfg(feature = "tmux_3_0")]
111    pub fn hooks(mut self) -> Self {
112        self.hooks = true;
113        self
114    }
115
116    /// `[-p]` - show window options
117    #[cfg(feature = "tmux_3_0")]
118    pub fn pane(mut self) -> Self {
119        self.pane = true;
120        self
121    }
122
123    /// `[-q]` - no error will be returned if `option` is unset
124    #[cfg(feature = "tmux_1_8")]
125    pub fn quiet(mut self) -> Self {
126        self.quiet = true;
127        self
128    }
129
130    /// `[-s]` - show the server options
131    #[cfg(feature = "tmux_1_2")]
132    pub fn server(mut self) -> Self {
133        self.server = true;
134        self
135    }
136
137    /// `[-v]` - shows only the option value
138    #[cfg(feature = "tmux_1_8")]
139    pub fn value(mut self) -> Self {
140        self.value = true;
141        self
142    }
143
144    /// `[-w]` - show the window options
145    #[cfg(feature = "tmux_1_2")]
146    pub fn window(mut self) -> Self {
147        self.window = true;
148        self
149    }
150
151    /// `[-t target-pane]` - target session or window name
152    //#[cfg(feature = "tmux_X_X")]
153    pub fn target<S: Into<Cow<'a, str>>>(mut self, target: S) -> Self {
154        self.target = Some(target.into());
155        self
156    }
157
158    /// `[option]` - specify option name
159    #[cfg(feature = "tmux_1_7")]
160    pub fn option<S: Into<Cow<'a, str>>>(mut self, option: S) -> Self {
161        self.option = Some(option.into());
162        self
163    }
164
165    pub fn build(self) -> TmuxCommand<'a> {
166        let mut cmd = TmuxCommand::new();
167
168        cmd.name(SHOW_OPTIONS);
169
170        // `[-A]` - includes options inherited from a parent set of options
171        #[cfg(feature = "tmux_3_0")]
172        if self.include_inherited {
173            cmd.push_flag(A_UPPERCASE_KEY);
174        }
175
176        // `[-g]` - global session or window options are listed
177        #[cfg(feature = "tmux_1_2")]
178        if self.global {
179            cmd.push_flag(G_LOWERCASE_KEY);
180        }
181
182        // `[-H]` - includes hooks (omitted by default)
183        #[cfg(feature = "tmux_3_0")]
184        if self.hooks {
185            cmd.push_flag(H_UPPERCASE_KEY);
186        }
187
188        // `[-p]` - show window options
189        #[cfg(feature = "tmux_3_0")]
190        if self.pane {
191            cmd.push_flag(P_LOWERCASE_KEY);
192        }
193
194        // `[-q]` - no error will be returned if `option` is unset
195        #[cfg(feature = "tmux_1_8")]
196        if self.quiet {
197            cmd.push_flag(Q_LOWERCASE_KEY);
198        }
199
200        // `[-s]` - show the server options
201        #[cfg(feature = "tmux_1_2")]
202        if self.server {
203            cmd.push_flag(S_LOWERCASE_KEY);
204        }
205
206        // `[-v]` - shows only the option value
207        #[cfg(feature = "tmux_1_8")]
208        if self.value {
209            cmd.push_flag(V_LOWERCASE_KEY);
210        }
211
212        // `[-w]` - show the window options
213        #[cfg(feature = "tmux_1_2")]
214        if self.window {
215            cmd.push_flag(W_LOWERCASE_KEY);
216        }
217
218        // `[-t target-pane]` - target session or window name
219        //#[cfg(feature = "tmux_X_X")]
220        if let Some(target) = self.target {
221            cmd.push_option(T_LOWERCASE_KEY, target);
222        }
223
224        // `[option]` - specify option name
225        #[cfg(feature = "tmux_1_7")]
226        if let Some(option) = self.option {
227            cmd.push_param(option);
228        }
229
230        cmd
231    }
232}