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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;

pub type Display<'a> = DisplayMessage<'a>;

/// Structure for displaying a message
///
/// # Manual
///
/// tmux ^3.4:
/// ```text
/// display-message [-aIlNpv] [-c target-client] [-d delay] [-t target-pane] [message]
///  (alias: display)
/// ```
///
/// tmux ^3.2:
/// ```text
/// display-message [-aINpv] [-c target-client] [-d delay] [-t target-pane] [message]
///  (alias: display)
/// ```
///
/// tmux ^3.0:
/// ```text
/// display-message [-aIpv] [-c target-client] [-t target-pane] [message]
///  (alias: display)
/// ```
///
/// tmux ^2.9a:
/// ```text
/// display-message [-apv] [-c target-client] [-t target-pane] [message]
///  (alias: display)
/// ```
///
/// tmux ^1.5:
/// ```text
/// display-message [-p] [-c target-client] [-t target-pane] [message]
///  (alias: display)
/// ```
///
/// tmux ^1.2:
/// ```text
/// display-message [-p] [-t target-client] [message]
///  (alias: display)
/// ```
///
/// tmux ^1.0:
/// ```text
/// display-message [-t target-client] [message]
///  (alias: display)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct DisplayMessage<'a> {
    /// `[-a]` - list the format variables and their values
    #[cfg(feature = "tmux_2_9a")]
    pub list_format_vars: bool,

    /// `[-I]` - forward any input read from stdin to the empty pane given by target-pane
    #[cfg(feature = "tmux_3_0")]
    pub forward_stdin: bool,

    /// `[-l]` - message is printed unchanged
    #[cfg(feature = "tmux_3_4")]
    pub disable_format: bool,

    /// `[-N]` - ignores key presses and closes only after the delay expires
    #[cfg(feature = "tmux_3_2")]
    pub ignore_keys: bool,

    /// `[-p]` - the output is printed to stdout
    #[cfg(feature = "tmux_2_9a")]
    pub print: bool,

    /// `[-v]` - print verbose logging as the format is parsed
    #[cfg(feature = "tmux_2_9a")]
    pub verbose: bool,

    /// `[-c target-client]` - target-client
    #[cfg(feature = "tmux_1_0")]
    pub target_client: Option<Cow<'a, str>>,

    /// `[-d delay]` - delay
    #[cfg(feature = "tmux_3_2")]
    pub delay: Option<usize>,

    /// `[-t target-pane]` - target-pane
    #[cfg(feature = "tmux_1_5")]
    pub target_pane: Option<Cow<'a, str>>,

    /// `[message]` - message
    #[cfg(feature = "tmux_1_0")]
    pub message: Option<Cow<'a, str>>,
}

impl<'a> DisplayMessage<'a> {
    pub fn new() -> Self {
        Default::default()
    }

    /// `[-a]` - list the format variables and their values
    #[cfg(feature = "tmux_2_9a")]
    pub fn list_format_vars(mut self) -> Self {
        self.list_format_vars = true;
        self
    }

    /// `[-I]` - forward any input read from stdin to the empty pane given by target-pane
    #[cfg(feature = "tmux_3_0")]
    pub fn forward_stdin(mut self) -> Self {
        self.forward_stdin = true;
        self
    }

    /// `[-l]` - message is printed unchanged
    #[cfg(feature = "tmux_3_4")]
    pub fn disable_format(mut self) -> Self {
        self.disable_format = true;
        self
    }

    /// `[-N]` - ignores key presses and closes only after the delay expires
    #[cfg(feature = "tmux_3_2")]
    pub fn ignore_keys(mut self) -> Self {
        self.ignore_keys = true;
        self
    }

    /// `[-p]` - the output is printed to stdout
    #[cfg(feature = "tmux_2_9a")]
    pub fn print(mut self) -> Self {
        self.print = true;
        self
    }

    /// `[-v]` - print verbose logging as the format is parsed
    #[cfg(feature = "tmux_2_9a")]
    pub fn verbose(mut self) -> Self {
        self.verbose = true;
        self
    }

    /// `[-c target-client]` - target-client
    #[cfg(feature = "tmux_1_0")]
    pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
        self.target_client = Some(target_client.into());
        self
    }

    /// `[-d delay]` - delay
    #[cfg(feature = "tmux_3_2")]
    pub fn delay(mut self, delay: usize) -> Self {
        self.delay = Some(delay);
        self
    }

    /// `[-t target-pane]` - target-pane
    #[cfg(feature = "tmux_1_5")]
    pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
        self.target_pane = Some(target_pane.into());
        self
    }

    /// `[message]` - message
    #[cfg(feature = "tmux_1_0")]
    pub fn message<S: Into<Cow<'a, str>>>(mut self, message: S) -> Self {
        self.message = Some(message.into());
        self
    }

    pub fn build(self) -> TmuxCommand<'a> {
        let mut cmd = TmuxCommand::new();

        cmd.name(DISPLAY_MESSAGE);

        // `[-a]` - list the format variables and their values
        #[cfg(feature = "tmux_2_9a")]
        if self.list_format_vars {
            cmd.push_flag(A_LOWERCASE_KEY);
        }

        // `[-I]` - forward any input read from stdin to the empty pane given by target-pane
        #[cfg(feature = "tmux_3_0")]
        if self.forward_stdin {
            cmd.push_flag(I_UPPERCASE_KEY);
        }

        // `[-l]` - message is printed unchanged
        #[cfg(feature = "tmux_3_4")]
        if self.forward_stdin {
            cmd.push_flag(L_LOWERCASE_KEY);
        }

        // `[-N]` - ignores key presses and closes only after the delay expires
        #[cfg(feature = "tmux_3_2")]
        if self.ignore_keys {
            cmd.push_flag(N_UPPERCASE_KEY);
        }

        // `[-p]` - the output is printed to stdout
        #[cfg(feature = "tmux_2_9a")]
        if self.print {
            cmd.push_flag(P_LOWERCASE_KEY);
        }

        // `[-v]` - print verbose logging as the format is parsed
        #[cfg(feature = "tmux_2_9a")]
        if self.verbose {
            cmd.push_flag(V_LOWERCASE_KEY);
        }

        // `[-c target-client]` - target-client
        #[cfg(feature = "tmux_1_0")]
        if let Some(target_client) = self.target_client {
            cmd.push_option(C_LOWERCASE_KEY, target_client);
        }

        // `[-d delay]` - delay
        #[cfg(feature = "tmux_3_2")]
        if let Some(delay) = self.delay {
            cmd.push_option(D_LOWERCASE_KEY, delay.to_string());
        }

        // `[-t target-pane]` - target-pane
        #[cfg(feature = "tmux_1_5")]
        if let Some(target_pane) = self.target_pane {
            cmd.push_option(T_LOWERCASE_KEY, target_pane);
        }

        // `[message]` - message
        #[cfg(feature = "tmux_1_0")]
        if let Some(message) = self.message {
            cmd.push_param(message);
        }

        cmd
    }
}