use crate::commands::constants::*;
use crate::PaneSize;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type MoveP<'a> = MovePane<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct MovePane<'a> {
#[cfg(feature = "tmux_1_7")]
pub left_above: bool,
#[cfg(feature = "tmux_1_7")]
pub detached: bool,
#[cfg(feature = "tmux_3_2")]
pub full_size: bool,
#[cfg(feature = "tmux_1_7")]
pub horizontal: bool,
#[cfg(feature = "tmux_1_7")]
pub vertical: bool,
#[cfg(feature = "tmux_1_7")]
pub size: Option<&'a PaneSize>,
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_3_1")))]
pub percentage: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_7")]
pub src_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_7")]
pub dst_pane: Option<Cow<'a, str>>,
}
impl<'a> MovePane<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_1_7")]
pub fn left_above(mut self) -> Self {
self.left_above = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn detached(mut self) -> Self {
self.detached = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn full_size(mut self) -> Self {
self.full_size = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn horizontal(mut self) -> Self {
self.horizontal = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn vertical(mut self) -> Self {
self.vertical = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn size(mut self, size: &'a PaneSize) -> Self {
self.size = Some(size);
self
}
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_3_1")))]
pub fn percentage<S: Into<Cow<'a, str>>>(mut self, percentage: S) -> Self {
self.percentage = Some(percentage.into());
self
}
#[cfg(feature = "tmux_1_7")]
pub fn src_pane<S: Into<Cow<'a, str>>>(mut self, src_pane: S) -> Self {
self.src_pane = Some(src_pane.into());
self
}
#[cfg(feature = "tmux_1_7")]
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(MOVE_PANE);
#[cfg(feature = "tmux_1_7")]
if self.left_above {
cmd.push_flag(B_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.detached {
cmd.push_flag(D_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.full_size {
cmd.push_flag(F_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.horizontal {
cmd.push_flag(H_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.vertical {
cmd.push_flag(V_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if let Some(size) = &self.size {
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_2_6")))]
match size {
PaneSize::Size(size) => cmd.push_option(L_LOWERCASE_KEY, size.to_string()),
PaneSize::Percentage(size) => {
cmd.push_option(L_LOWERCASE_KEY, format!("{}%", size))
}
};
#[cfg(feature = "tmux_2_6")]
match size {
PaneSize::Size(size) => cmd.push_option(L_LOWERCASE_KEY, size.to_string()),
PaneSize::Percentage(size) => cmd.push_option(P_LOWERCASE_KEY, size.to_string()),
};
}
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_3_1")))]
if let Some(percentage) = self.percentage {
cmd.push_option(P_LOWERCASE_KEY, percentage);
}
#[cfg(feature = "tmux_1_7")]
if let Some(src_pane) = self.src_pane {
cmd.push_option(S_LOWERCASE_KEY, src_pane);
}
#[cfg(feature = "tmux_1_7")]
if let Some(dst_pane) = self.dst_pane {
cmd.push_option(T_LOWERCASE_KEY, dst_pane);
}
cmd
}
}