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

pub type SelectL<'a> = SelectLayout<'a>;

/// Choose a specific layout for a window
///
/// # Manual
///
/// tmux ^2.7:
/// ```text
/// select-layout [-Enop] [-t target-pane] [layout-name]
/// (alias: selectl)
/// ```
///
/// tmux ^2.1:
/// ```text
/// select-layout [-nop] [-t target-pane] [layout-name]
/// (alias: selectl)
/// ```
///
/// tmux ^1.5:
/// ```text
/// select-layout [-np] [-t target-pane] [layout-name]
/// (alias: selectl)
/// ```
///
/// tmux ^1.0:
/// ```text
/// select-layout [-t target-pane] [layout-name]
/// (alias: selectl)
/// ```
///
/// tmux ^0.9:
/// ```text
/// select-layout [-t target-pane] layout-name
/// (alias: selectl)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SelectLayout<'a> {
    /// `[-E]` - spread the current pane and any panes next to it out evenly
    #[cfg(feature = "tmux_2_7")]
    pub spread: bool,

    /// `[-n]` - next-layout equivalent
    #[cfg(feature = "tmux_1_5")]
    pub next_layout: bool,

    /// `[-o]` - apply the last set layout if possible
    #[cfg(feature = "tmux_2_1")]
    pub last_layout: bool,

    /// `[-p]` - previous-layout equivalent
    #[cfg(feature = "tmux_1_5")]
    pub previous_layout: bool,

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

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

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

    /// `[-E]` - spread the current pane and any panes next to it out evenly
    #[cfg(feature = "tmux_2_7")]
    pub fn spread(mut self) -> Self {
        self.spread = true;
        self
    }

    /// `[-n]` - next-layout equivalent
    #[cfg(feature = "tmux_1_5")]
    pub fn next_layout(mut self) -> Self {
        self.next_layout = true;
        self
    }

    /// `[-o]` - apply the last set layout if possible
    #[cfg(feature = "tmux_2_1")]
    pub fn last_layout(mut self) -> Self {
        self.last_layout = true;
        self
    }

    /// `[-p]` - previous-layout equivalent
    #[cfg(feature = "tmux_1_5")]
    pub fn previous_layout(mut self) -> Self {
        self.previous_layout = true;
        self
    }

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

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

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

        cmd.name(SELECT_LAYOUT);

        // `[-E]` - spread the current pane and any panes next to it out evenly
        #[cfg(feature = "tmux_2_7")]
        if self.spread {
            cmd.push_flag(E_UPPERCASE_KEY);
        }

        // `[-n]` - next-layout equivalent
        #[cfg(feature = "tmux_1_5")]
        if self.next_layout {
            cmd.push_flag(N_LOWERCASE_KEY);
        }

        // `[-o]` - apply the last set layout if possible
        #[cfg(feature = "tmux_2_1")]
        if self.last_layout {
            cmd.push_flag(O_LOWERCASE_KEY);
        }

        // `[-p]` - previous-layout equivalent
        #[cfg(feature = "tmux_1_5")]
        if self.previous_layout {
            cmd.push_flag(P_LOWERCASE_KEY);
        }

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

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

        cmd
    }
}