tmux_interface/commands/windows_and_panes/
select_layout.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type SelectL<'a> = SelectLayout<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
41pub struct SelectLayout<'a> {
42 #[cfg(feature = "tmux_2_7")]
44 pub spread: bool,
45
46 #[cfg(feature = "tmux_1_5")]
48 pub next_layout: bool,
49
50 #[cfg(feature = "tmux_2_1")]
52 pub last_layout: bool,
53
54 #[cfg(feature = "tmux_1_5")]
56 pub previous_layout: bool,
57
58 #[cfg(feature = "tmux_0_9")]
60 pub target_pane: Option<Cow<'a, str>>,
61
62 #[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 #[cfg(feature = "tmux_2_7")]
74 pub fn spread(mut self) -> Self {
75 self.spread = true;
76 self
77 }
78
79 #[cfg(feature = "tmux_1_5")]
81 pub fn next_layout(mut self) -> Self {
82 self.next_layout = true;
83 self
84 }
85
86 #[cfg(feature = "tmux_2_1")]
88 pub fn last_layout(mut self) -> Self {
89 self.last_layout = true;
90 self
91 }
92
93 #[cfg(feature = "tmux_1_5")]
95 pub fn previous_layout(mut self) -> Self {
96 self.previous_layout = true;
97 self
98 }
99
100 #[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 #[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 #[cfg(feature = "tmux_2_7")]
121 if self.spread {
122 cmd.push_flag(E_UPPERCASE_KEY);
123 }
124
125 #[cfg(feature = "tmux_1_5")]
127 if self.next_layout {
128 cmd.push_flag(N_LOWERCASE_KEY);
129 }
130
131 #[cfg(feature = "tmux_2_1")]
133 if self.last_layout {
134 cmd.push_flag(O_LOWERCASE_KEY);
135 }
136
137 #[cfg(feature = "tmux_1_5")]
139 if self.previous_layout {
140 cmd.push_flag(P_LOWERCASE_KEY);
141 }
142
143 #[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 #[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}