tmux_interface/commands/windows_and_panes/
select_layout.rs

1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type SelectL<'a> = SelectLayout<'a>;
6
7/// Choose a specific layout for a window
8///
9/// # Manual
10///
11/// tmux ^2.7:
12/// ```text
13/// select-layout [-Enop] [-t target-pane] [layout-name]
14/// (alias: selectl)
15/// ```
16///
17/// tmux ^2.1:
18/// ```text
19/// select-layout [-nop] [-t target-pane] [layout-name]
20/// (alias: selectl)
21/// ```
22///
23/// tmux ^1.5:
24/// ```text
25/// select-layout [-np] [-t target-pane] [layout-name]
26/// (alias: selectl)
27/// ```
28///
29/// tmux ^1.0:
30/// ```text
31/// select-layout [-t target-pane] [layout-name]
32/// (alias: selectl)
33/// ```
34///
35/// tmux ^0.9:
36/// ```text
37/// select-layout [-t target-pane] layout-name
38/// (alias: selectl)
39/// ```
40#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
41pub struct SelectLayout<'a> {
42    /// `[-E]` - spread the current pane and any panes next to it out evenly
43    #[cfg(feature = "tmux_2_7")]
44    pub spread: bool,
45
46    /// `[-n]` - next-layout equivalent
47    #[cfg(feature = "tmux_1_5")]
48    pub next_layout: bool,
49
50    /// `[-o]` - apply the last set layout if possible
51    #[cfg(feature = "tmux_2_1")]
52    pub last_layout: bool,
53
54    /// `[-p]` - previous-layout equivalent
55    #[cfg(feature = "tmux_1_5")]
56    pub previous_layout: bool,
57
58    /// `[-t target-pane]` - target-pane
59    #[cfg(feature = "tmux_0_9")]
60    pub target_pane: Option<Cow<'a, str>>,
61
62    /// `[layout-name]` - layout-name
63    #[cfg(feature = "tmux_1_0")]
64    pub layout_name: Option<Cow<'a, str>>,
65}
66
67impl<'a> SelectLayout<'a> {
68    pub fn new() -> Self {
69        Default::default()
70    }
71
72    /// `[-E]` - spread the current pane and any panes next to it out evenly
73    #[cfg(feature = "tmux_2_7")]
74    pub fn spread(mut self) -> Self {
75        self.spread = true;
76        self
77    }
78
79    /// `[-n]` - next-layout equivalent
80    #[cfg(feature = "tmux_1_5")]
81    pub fn next_layout(mut self) -> Self {
82        self.next_layout = true;
83        self
84    }
85
86    /// `[-o]` - apply the last set layout if possible
87    #[cfg(feature = "tmux_2_1")]
88    pub fn last_layout(mut self) -> Self {
89        self.last_layout = true;
90        self
91    }
92
93    /// `[-p]` - previous-layout equivalent
94    #[cfg(feature = "tmux_1_5")]
95    pub fn previous_layout(mut self) -> Self {
96        self.previous_layout = true;
97        self
98    }
99
100    /// `[-t target-pane]` - target-pane
101    #[cfg(feature = "tmux_0_9")]
102    pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
103        self.target_pane = Some(target_pane.into());
104        self
105    }
106
107    /// `[layout-name]` - layout-name
108    #[cfg(feature = "tmux_1_0")]
109    pub fn layout_name<S: Into<Cow<'a, str>>>(mut self, layout_name: S) -> Self {
110        self.layout_name = Some(layout_name.into());
111        self
112    }
113
114    pub fn build(self) -> TmuxCommand<'a> {
115        let mut cmd = TmuxCommand::new();
116
117        cmd.name(SELECT_LAYOUT);
118
119        // `[-E]` - spread the current pane and any panes next to it out evenly
120        #[cfg(feature = "tmux_2_7")]
121        if self.spread {
122            cmd.push_flag(E_UPPERCASE_KEY);
123        }
124
125        // `[-n]` - next-layout equivalent
126        #[cfg(feature = "tmux_1_5")]
127        if self.next_layout {
128            cmd.push_flag(N_LOWERCASE_KEY);
129        }
130
131        // `[-o]` - apply the last set layout if possible
132        #[cfg(feature = "tmux_2_1")]
133        if self.last_layout {
134            cmd.push_flag(O_LOWERCASE_KEY);
135        }
136
137        // `[-p]` - previous-layout equivalent
138        #[cfg(feature = "tmux_1_5")]
139        if self.previous_layout {
140            cmd.push_flag(P_LOWERCASE_KEY);
141        }
142
143        // `[-t target-pane]` - target-pane
144        #[cfg(feature = "tmux_0_9")]
145        if let Some(target_pane) = self.target_pane {
146            cmd.push_option(T_LOWERCASE_KEY, target_pane);
147        }
148
149        // `[layout-name]` - layout-name
150        #[cfg(feature = "tmux_1_0")]
151        if let Some(layout_name) = self.layout_name {
152            cmd.push_param(layout_name);
153        }
154
155        cmd
156    }
157}