use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type SwapP<'a> = SwapPane<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SwapPane<'a> {
#[cfg(feature = "tmux_0_8")]
pub detached: bool,
#[cfg(feature = "tmux_0_8")]
pub previous_pane: bool,
#[cfg(feature = "tmux_0_8")]
pub next_pane: bool,
#[cfg(feature = "tmux_3_1")]
pub keep_zoomed: bool,
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub src_index: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub src_pane: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub dst_index: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub target_window: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub dst_pane: Option<Cow<'a, str>>,
}
impl<'a> SwapPane<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_0_8")]
pub fn detached(mut self) -> Self {
self.detached = true;
self
}
#[cfg(feature = "tmux_0_8")]
pub fn previous_pane(mut self) -> Self {
self.previous_pane = true;
self
}
#[cfg(feature = "tmux_0_8")]
pub fn next_pane(mut self) -> Self {
self.next_pane = true;
self
}
#[cfg(feature = "tmux_3_1")]
pub fn keep_zoomed(mut self) -> Self {
self.keep_zoomed = true;
self
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub fn src_index<S: Into<Cow<'a, str>>>(mut self, src_index: S) -> Self {
self.src_index = Some(src_index.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn src_pane<S: Into<Cow<'a, str>>>(mut self, src_pane: S) -> Self {
self.src_pane = Some(src_pane.into());
self
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub fn dst_index<S: Into<Cow<'a, str>>>(mut self, dst_index: S) -> Self {
self.dst_index = Some(dst_index.into());
self
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
pub fn target_window<S: Into<Cow<'a, str>>>(mut self, target_window: S) -> Self {
self.target_window = Some(target_window.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn dst_pane<S: Into<Cow<'a, str>>>(mut self, dst_pane: S) -> Self {
self.dst_pane = Some(dst_pane.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SWAP_PANE);
#[cfg(feature = "tmux_0_8")]
if self.detached {
cmd.push_flag(D_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_0_8")]
if self.previous_pane {
cmd.push_flag(D_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_0_8")]
if self.next_pane {
cmd.push_flag(U_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_1")]
if self.keep_zoomed {
cmd.push_flag(Z_UPPERCASE_KEY);
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
if let Some(src_index) = self.src_index {
cmd.push_option(P_LOWERCASE_KEY, src_index);
}
#[cfg(feature = "tmux_1_5")]
if let Some(src_pane) = self.src_pane {
cmd.push_option(S_LOWERCASE_KEY, src_pane);
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
if let Some(dst_index) = self.dst_index {
cmd.push_option(Q_LOWERCASE_KEY, dst_index);
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
#[cfg(feature = "tmux_1_5")]
if let Some(dst_pane) = self.dst_pane {
cmd.push_option(T_LOWERCASE_KEY, dst_pane);
}
cmd
}
}