tmux_interface/commands/miscellaneous/
wait_for.rs

1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type Wait<'a> = WaitFor<'a>;
6
7// TODO: enum for arg
8// FIXME: not multiple, only one choice
9/// # Manual
10///
11/// tmux ^1.9:
12/// ```text
13/// wait-for [-L | -S | -U] channel
14/// (alias: wait)
15/// ```
16///
17/// tmux ^1.8:
18/// ```text
19/// wait-for -LSU channel
20/// (alias: wait)
21/// ```
22#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
23pub struct WaitFor<'a> {
24    /// `[-L]`
25    #[cfg(feature = "tmux_1_8")]
26    pub locked: bool,
27
28    /// `[-S]`
29    #[cfg(feature = "tmux_1_8")]
30    pub woken: bool,
31
32    /// `[-U]`
33    #[cfg(feature = "tmux_1_8")]
34    pub unlocked: bool,
35
36    /// `channel`
37    #[cfg(feature = "tmux_1_8")]
38    pub channel: Option<Cow<'a, str>>,
39}
40
41impl<'a> WaitFor<'a> {
42    pub fn new() -> Self {
43        Default::default()
44    }
45
46    /// `[-L]`
47    #[cfg(feature = "tmux_1_8")]
48    pub fn locked(mut self) -> Self {
49        self.locked = true;
50        self
51    }
52
53    /// `[-S]`
54    #[cfg(feature = "tmux_1_8")]
55    pub fn woken(mut self) -> Self {
56        self.woken = true;
57        self
58    }
59
60    /// `[-U]`
61    #[cfg(feature = "tmux_1_8")]
62    pub fn unlocked(mut self) -> Self {
63        self.unlocked = true;
64        self
65    }
66
67    /// `channel`
68    #[cfg(feature = "tmux_1_8")]
69    pub fn channel<S: Into<Cow<'a, str>>>(mut self, channel: S) -> Self {
70        self.channel = Some(channel.into());
71        self
72    }
73
74    pub fn build(self) -> TmuxCommand<'a> {
75        let mut cmd = TmuxCommand::new();
76
77        cmd.name(WAIT_FOR);
78
79        // `[-L]`
80        #[cfg(feature = "tmux_1_8")]
81        if self.locked {
82            cmd.push_flag(L_UPPERCASE_KEY);
83        }
84
85        // `[-S]`
86        #[cfg(feature = "tmux_1_8")]
87        if self.woken {
88            cmd.push_flag(S_UPPERCASE_KEY);
89        }
90
91        // `[-U]`
92        #[cfg(feature = "tmux_1_8")]
93        if self.unlocked {
94            cmd.push_flag(U_UPPERCASE_KEY);
95        }
96
97        // `channel`
98        #[cfg(feature = "tmux_1_8")]
99        if let Some(channel) = self.channel {
100            cmd.push_param(channel);
101        }
102        cmd
103    }
104}