use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type RespawnP<'a> = RespawnPane<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct RespawnPane<'a> {
#[cfg(feature = "tmux_1_5")]
pub kill: bool,
#[cfg(feature = "tmux_2_6")]
pub start_directory: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_0")]
pub environment: Option<Cow<'a, str>>,
#[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> RespawnPane<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_1_5")]
pub fn kill(mut self) -> Self {
self.kill = true;
self
}
#[cfg(feature = "tmux_2_6")]
pub fn start_directory<S: Into<Cow<'a, str>>>(mut self, start_directory: S) -> Self {
self.start_directory = Some(start_directory.into());
self
}
#[cfg(feature = "tmux_3_0")]
pub fn environment<S: Into<Cow<'a, str>>>(mut self, environment: S) -> Self {
self.environment = Some(environment.into());
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(RESPAWN_PANE);
#[cfg(feature = "tmux_1_5")]
if self.kill {
cmd.push_flag(K_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_2_6")]
if let Some(start_directory) = self.start_directory {
cmd.push_option(C_LOWERCASE_KEY, start_directory);
}
#[cfg(feature = "tmux_3_0")]
if let Some(environment) = self.environment {
cmd.push_option(E_LOWERCASE_KEY, environment);
}
#[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
}
}