tmux_interface/commands/clients_and_sessions/
show_messages.rs

1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type ShowMsgs<'a> = ShowMessages<'a>;
6
7/// Show client messages or server information
8///
9/// # Manual
10///
11/// tmux ^2.2:
12/// ```text
13/// show-messages [-JT] [-t target-client]
14/// (alias: showmsgs)
15/// ```
16///
17/// tmux ^1.9:
18/// ```text
19/// show-messages [-IJT] [-t target-client]
20/// (alias: showmsgs)
21/// ```
22///
23/// tmux ^1.2:
24/// ```text
25/// show-messages [-t target-client]
26/// (alias: showmsgs)
27/// ```
28#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct ShowMessages<'a> {
30    /// `[-I]`
31    #[cfg(all(feature = "tmux_1_9", not(feature = "tmux_2_2")))]
32    pub server: bool,
33    /// `[-J]`
34    #[cfg(feature = "tmux_1_9")]
35    pub jobs: bool,
36    /// `[-T]`
37    #[cfg(feature = "tmux_1_9")]
38    pub terminals: bool,
39    /// `[-t target-client]`
40    #[cfg(feature = "tmux_1_2")]
41    pub target_client: Option<Cow<'a, str>>,
42}
43
44impl<'a> ShowMessages<'a> {
45    pub fn new() -> Self {
46        Default::default()
47    }
48
49    /// `[-I]`
50    #[cfg(all(feature = "tmux_1_9", not(feature = "tmux_2_2")))]
51    pub fn server(mut self) -> Self {
52        self.server = true;
53        self
54    }
55
56    /// `[-J]`
57    #[cfg(feature = "tmux_1_9")]
58    pub fn jobs(mut self) -> Self {
59        self.jobs = true;
60        self
61    }
62
63    /// `[-T]`
64    #[cfg(feature = "tmux_1_9")]
65    pub fn terminals(mut self) -> Self {
66        self.terminals = true;
67        self
68    }
69
70    /// `[-t target-client]`
71    #[cfg(feature = "tmux_1_2")]
72    pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
73        self.target_client = Some(target_client.into());
74        self
75    }
76
77    pub fn build(self) -> TmuxCommand<'a> {
78        let mut cmd = TmuxCommand::new();
79
80        cmd.name(SHOW_MESSAGES);
81
82        // `[-I]`
83        #[cfg(all(feature = "tmux_1_9", not(feature = "tmux_2_2")))]
84        if self.server {
85            cmd.push_flag(I_UPPERCASE_KEY);
86        }
87
88        // `[-J]`
89        #[cfg(feature = "tmux_1_9")]
90        if self.jobs {
91            cmd.push_flag(J_UPPERCASE_KEY);
92        }
93
94        // `[-T]`
95        #[cfg(feature = "tmux_1_9")]
96        if self.terminals {
97            cmd.push_flag(T_UPPERCASE_KEY);
98        }
99
100        // `[-t target-client]`
101        #[cfg(feature = "tmux_1_2")]
102        if let Some(target_client) = self.target_client {
103            cmd.push_option(T_LOWERCASE_KEY, target_client);
104        }
105
106        cmd
107    }
108}