tmux_interface/commands/windows_and_panes/
swap_pane.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4use std::marker::PhantomData;
5
6pub type SwapP<'a> = SwapPane<'a>;
7
8#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
30pub struct SwapPane<'a> {
31 #[cfg(feature = "tmux_0_8")]
33 pub detached: bool,
34
35 #[cfg(feature = "tmux_0_8")]
37 pub previous_pane: bool,
38
39 #[cfg(feature = "tmux_0_8")]
41 pub next_pane: bool,
42
43 #[cfg(feature = "tmux_3_1")]
45 pub keep_zoomed: bool,
46
47 #[cfg(feature = "tmux_1_0")]
49 pub src_pane: Option<Cow<'a, str>>,
50
51 #[cfg(feature = "tmux_1_0")]
53 pub dst_pane: Option<Cow<'a, str>>,
54
55 _phantom_data: PhantomData<&'a ()>,
56}
57
58impl<'a> SwapPane<'a> {
59 pub fn new() -> Self {
60 Default::default()
61 }
62
63 #[cfg(feature = "tmux_0_8")]
65 pub fn detached(mut self) -> Self {
66 self.detached = true;
67 self
68 }
69
70 #[cfg(feature = "tmux_0_8")]
72 pub fn previous_pane(mut self) -> Self {
73 self.previous_pane = true;
74 self
75 }
76
77 #[cfg(feature = "tmux_0_8")]
79 pub fn next_pane(mut self) -> Self {
80 self.next_pane = true;
81 self
82 }
83
84 #[cfg(feature = "tmux_3_1")]
86 pub fn keep_zoomed(mut self) -> Self {
87 self.keep_zoomed = true;
88 self
89 }
90
91 #[cfg(feature = "tmux_1_0")]
93 pub fn src_pane<S: Into<Cow<'a, str>>>(mut self, src_pane: S) -> Self {
94 self.src_pane = Some(src_pane.into());
95 self
96 }
97
98 #[cfg(feature = "tmux_1_0")]
100 pub fn dst_pane<S: Into<Cow<'a, str>>>(mut self, dst_pane: S) -> Self {
101 self.dst_pane = Some(dst_pane.into());
102 self
103 }
104
105 pub fn build(self) -> TmuxCommand<'a> {
106 let mut cmd = TmuxCommand::new();
107
108 cmd.name(SWAP_PANE);
109
110 #[cfg(feature = "tmux_0_8")]
112 if self.detached {
113 cmd.push_flag(D_LOWERCASE_KEY);
114 }
115
116 #[cfg(feature = "tmux_0_8")]
118 if self.previous_pane {
119 cmd.push_flag(D_UPPERCASE_KEY);
120 }
121
122 #[cfg(feature = "tmux_0_8")]
124 if self.next_pane {
125 cmd.push_flag(U_UPPERCASE_KEY);
126 }
127
128 #[cfg(feature = "tmux_3_1")]
130 if self.keep_zoomed {
131 cmd.push_flag(Z_UPPERCASE_KEY);
132 }
133
134 #[cfg(feature = "tmux_1_0")]
136 if let Some(src_pane) = self.src_pane {
137 cmd.push_option(S_LOWERCASE_KEY, src_pane);
138 }
139
140 #[cfg(feature = "tmux_1_0")]
142 if let Some(dst_pane) = self.dst_pane {
143 cmd.push_option(T_LOWERCASE_KEY, dst_pane);
144 }
145
146 cmd
147 }
148}