use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type SelectL<'a> = SelectLayout<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SelectLayout<'a> {
#[cfg(feature = "tmux_2_7")]
pub spread: bool,
#[cfg(feature = "tmux_1_5")]
pub next_layout: bool,
#[cfg(feature = "tmux_2_1")]
pub last_layout: bool,
#[cfg(feature = "tmux_1_5")]
pub previous_layout: bool,
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_7")))]
pub target_window: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_2_7")]
pub target_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub layout_name: Option<Cow<'a, str>>,
}
impl<'a> SelectLayout<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_2_7")]
pub fn spread(mut self) -> Self {
self.spread = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn next_layout(mut self) -> Self {
self.next_layout = true;
self
}
#[cfg(feature = "tmux_2_1")]
pub fn last_layout(mut self) -> Self {
self.last_layout = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn previous_layout(mut self) -> Self {
self.previous_layout = true;
self
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_7")))]
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_2_7")]
pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
self.target_pane = Some(target_pane.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn layout_name<S: Into<Cow<'a, str>>>(mut self, layout_name: S) -> Self {
self.layout_name = Some(layout_name.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SELECT_LAYOUT);
#[cfg(feature = "tmux_2_7")]
if self.spread {
cmd.push_flag(E_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.next_layout {
cmd.push_flag(N_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_2_1")]
if self.last_layout {
cmd.push_flag(O_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.previous_layout {
cmd.push_flag(P_LOWERCASE_KEY);
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_7")))]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
#[cfg(feature = "tmux_2_7")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
#[cfg(feature = "tmux_1_5")]
if let Some(layout_name) = self.layout_name {
cmd.push_param(layout_name);
}
cmd
}
}