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
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;

// TODO: enum for arg
// FIXME: not multiple, only one choice
/// # Manual
///
/// tmux ^1.9:
/// ```text
/// wait-for [-L | -S | -U] channel
/// (alias: wait)
/// ```
///
/// tmux ^1.8:
/// ```text
/// wait-for -LSU channel
/// (alias: wait)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct WaitFor<'a> {
    /// `[-L]`
    #[cfg(feature = "tmux_1_8")]
    pub locked: bool,

    /// `[-S]`
    #[cfg(feature = "tmux_1_8")]
    pub woken: bool,

    /// `[-U]`
    #[cfg(feature = "tmux_1_8")]
    pub unlocked: bool,

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

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

    /// `[-L]`
    #[cfg(feature = "tmux_1_8")]
    pub fn locked(mut self) -> Self {
        self.locked = true;
        self
    }

    /// `[-S]`
    #[cfg(feature = "tmux_1_8")]
    pub fn woken(mut self) -> Self {
        self.woken = true;
        self
    }

    /// `[-U]`
    #[cfg(feature = "tmux_1_8")]
    pub fn unlocked(mut self) -> Self {
        self.unlocked = true;
        self
    }

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

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

        cmd.name(WAIT_FOR);

        // `[-L]`
        #[cfg(feature = "tmux_1_8")]
        if self.locked {
            cmd.push_flag(L_UPPERCASE_KEY);
        }

        // `[-S]`
        #[cfg(feature = "tmux_1_8")]
        if self.woken {
            cmd.push_flag(S_UPPERCASE_KEY);
        }

        // `[-U]`
        #[cfg(feature = "tmux_1_8")]
        if self.unlocked {
            cmd.push_flag(U_UPPERCASE_KEY);
        }

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