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

pub type DisplayP<'a> = DisplayPanes<'a>;

/// Display a visible indicator of each pane shown by `target-client`
///
/// # Manual
///
/// tmux ^3.2:
/// ```text
/// display-panes [-bN] [-d duration] [-t target-client] [template]
/// (alias: displayp)
/// ```
///
/// tmux ^2.9:
/// ```text
/// display-panes [-b] [-d duration] [-t target-client] [template]
/// (alias: displayp)
/// ```
///
/// tmux ^2.6:
/// ```text
/// display-panes [-d duration] [-t target-client] [template]
/// (alias: displayp)
/// ```
///
/// tmux ^2.3:
/// ```text
/// display-panes [-t target-client] [template]
/// (alias: displayp)
/// ```
///
/// tmux ^1.0:
/// ```text
/// display-panes [-t target-client]
/// (alias: displayp)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct DisplayPanes<'a> {
    /// `[-b]`
    #[cfg(feature = "tmux_2_9")]
    pub not_block: bool,

    /// `[-N]`
    #[cfg(feature = "tmux_3_2")]
    pub ignore_keys: bool,

    // XXX: type?
    /// `[-d duration]`
    #[cfg(feature = "tmux_2_6")]
    pub duration: Option<Cow<'a, str>>,

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

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

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

    /// `[-b]`
    #[cfg(feature = "tmux_2_9")]
    pub fn not_block(mut self) -> Self {
        self.not_block = true;
        self
    }

    /// `[-N]`
    #[cfg(feature = "tmux_3_2")]
    pub fn ignore_keys(mut self) -> Self {
        self.ignore_keys = true;
        self
    }

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

    /// `[-d 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
    }

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

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

        cmd.name(DISPLAY_PANES);

        // `[-b]`
        #[cfg(feature = "tmux_2_9")]
        if self.not_block {
            cmd.push_flag(B_LOWERCASE_KEY);
        }

        // `[-N]`
        #[cfg(feature = "tmux_3_2")]
        if self.ignore_keys {
            cmd.push_flag(N_UPPERCASE_KEY);
        }

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

        // `[-d duration]`
        #[cfg(feature = "tmux_1_0")]
        if let Some(target_client) = self.target_client {
            cmd.push_option(T_LOWERCASE_KEY, target_client);
        }

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

        cmd
    }
}