use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type PipeP<'a> = PipePane<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct PipePane<'a> {
#[cfg(feature = "tmux_2_7")]
pub stdout: bool,
#[cfg(feature = "tmux_2_7")]
pub stdin: bool,
#[cfg(feature = "tmux_1_5")]
pub open: bool,
#[cfg(feature = "tmux_1_5")]
pub target_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub shell_command: Option<Cow<'a, str>>,
}
impl<'a> PipePane<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_2_7")]
pub fn stdout(mut self) -> Self {
self.stdout = true;
self
}
#[cfg(feature = "tmux_2_7")]
pub fn stdin(mut self) -> Self {
self.stdin = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn open(mut self) -> Self {
self.open = true;
self
}
#[cfg(feature = "tmux_1_5")]
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 shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
self.shell_command = Some(shell_command.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(PIPE_PANE);
#[cfg(feature = "tmux_2_7")]
if self.stdout {
cmd.push_flag(I_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_2_7")]
if self.stdin {
cmd.push_flag(O_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.open {
cmd.push_flag(O_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
#[cfg(feature = "tmux_1_5")]
if let Some(shell_command) = self.shell_command {
cmd.push_param(shell_command);
}
cmd
}
}