use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type FindW<'a> = FindWindow<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct FindWindow<'a> {
#[cfg(feature = "tmux_3_2")]
pub ignore_case: bool,
#[cfg(feature = "tmux_1_7")]
pub only_visible: bool,
#[cfg(feature = "tmux_1_7")]
pub only_name: bool,
#[cfg(feature = "tmux_3_0a")]
pub regex: bool,
#[cfg(feature = "tmux_1_7")]
pub only_title: bool,
#[cfg(feature = "tmux_2_9")]
pub zoom: bool,
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_2_6")))]
pub format: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_6")))]
pub target_window: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_2_6")]
pub target_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_0_8")]
pub match_string: Option<Cow<'a, str>>,
}
impl<'a> FindWindow<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_3_2")]
pub fn ignore_case(mut self) -> Self {
self.ignore_case = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn only_visible(mut self) -> Self {
self.only_visible = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn only_name(mut self) -> Self {
self.only_name = true;
self
}
#[cfg(feature = "tmux_3_0a")]
pub fn regex(mut self) -> Self {
self.regex = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn only_title(mut self) -> Self {
self.only_title = true;
self
}
#[cfg(feature = "tmux_2_9")]
pub fn zoom(mut self) -> Self {
self.zoom = true;
self
}
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_2_6")))]
pub fn format<S: Into<Cow<'a, str>>>(mut self, format: S) -> Self {
self.format = Some(format.into());
self
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_6")))]
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_6")]
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_0_8")]
pub fn match_string<S: Into<Cow<'a, str>>>(mut self, match_string: S) -> Self {
self.match_string = Some(match_string.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(FIND_WINDOW);
#[cfg(feature = "tmux_3_2")]
if self.ignore_case {
cmd.push_flag(I_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.only_visible {
cmd.push_flag(C_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.only_name {
cmd.push_flag(N_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_0a")]
if self.regex {
cmd.push_flag(R_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.only_title {
cmd.push_flag(T_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_2_9")]
if self.zoom {
cmd.push_flag(Z_UPPERCASE_KEY);
}
#[cfg(all(feature = "tmux_1_7", not(feature = "tmux_2_6")))]
if let Some(format) = self.format {
cmd.push_option(F_UPPERCASE_KEY, format);
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_6")))]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
#[cfg(feature = "tmux_2_6")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
#[cfg(feature = "tmux_0_8")]
if let Some(match_string) = self.match_string {
cmd.push_param(match_string);
}
cmd
}
}