use crate::commands::constants::*;
#[cfg(feature = "tmux_3_3")]
use crate::PromptType;
use crate::TmuxCommand;
use std::borrow::Cow;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct CommandPrompt<'a> {
#[cfg(feature = "tmux_2_4")]
pub one_keypress: bool,
#[cfg(feature = "tmux_3_3")]
pub background: bool,
#[cfg(feature = "tmux_3_3")]
pub expand_as_format: bool,
#[cfg(feature = "tmux_2_4")]
pub on_input_change: bool,
#[cfg(feature = "tmux_3_1")]
pub key_name: bool,
#[cfg(feature = "tmux_3_6")]
pub disable_splitting: bool,
#[cfg(feature = "tmux_3_0a")]
pub numeric: bool,
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
pub prompt_type: bool,
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
pub for_window: bool,
#[cfg(feature = "tmux_1_5")]
pub inputs: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_1_5")]
pub prompts: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_0_8")]
pub target_client: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_3")]
pub prompt_type: Option<PromptType>,
#[cfg(feature = "tmux_0_8")]
pub template: Option<Cow<'a, str>>,
}
impl<'a> CommandPrompt<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_2_4")]
pub fn one_keypress(mut self) -> Self {
self.one_keypress = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn background(mut self) -> Self {
self.background = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn expand_as_format(mut self) -> Self {
self.expand_as_format = true;
self
}
#[cfg(feature = "tmux_2_4")]
pub fn on_input_change(mut self) -> Self {
self.on_input_change = true;
self
}
#[cfg(feature = "tmux_3_1")]
pub fn key_name(mut self) -> Self {
self.key_name = true;
self
}
#[cfg(feature = "tmux_3_6")]
pub fn disable_splitting(mut self) -> Self {
self.disable_splitting = true;
self
}
#[cfg(feature = "tmux_3_0a")]
pub fn numeric(mut self) -> Self {
self.numeric = true;
self
}
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
pub fn prompt_type(mut self) -> Self {
self.prompt_type = true;
self
}
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
pub fn for_window(mut self) -> Self {
self.for_window = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn inputs<S: Into<Cow<'a, str>>>(mut self, inputs: S) -> Self {
self.inputs = Some(inputs.into());
self
}
#[cfg(feature = "tmux_1_5")]
pub fn prompts<S: Into<Cow<'a, str>>>(mut self, prompts: S) -> Self {
self.prompts = Some(prompts.into());
self
}
#[cfg(feature = "tmux_0_8")]
pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
self.target_client = Some(target_client.into());
self
}
#[cfg(feature = "tmux_3_3")]
pub fn prompt_type(mut self, prompt_type: PromptType) -> Self {
self.prompt_type = Some(prompt_type);
self
}
#[cfg(feature = "tmux_0_8")]
pub fn template<S: Into<Cow<'a, str>>>(mut self, template: S) -> Self {
self.template = Some(template.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(COMMAND_PROMPT);
#[cfg(feature = "tmux_2_4")]
if self.one_keypress {
cmd.push_flag(_1_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.background {
cmd.push_flag(B_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if self.expand_as_format {
cmd.push_flag(F_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_2_4")]
if self.on_input_change {
cmd.push_flag(I_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_1")]
if self.key_name {
cmd.push_flag(K_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_6")]
if self.disable_splitting {
cmd.push_flag(L_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_0a")]
if self.numeric {
cmd.push_flag(N_UPPERCASE_KEY);
}
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
if self.prompt_type {
cmd.push_flag(T_UPPERCASE_KEY);
}
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
if self.for_window {
cmd.push_flag(W_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if let Some(inputs) = self.inputs {
cmd.push_option(I_UPPERCASE_KEY, inputs);
}
#[cfg(feature = "tmux_1_5")]
if let Some(prompts) = self.prompts {
cmd.push_option(P_LOWERCASE_KEY, prompts);
}
#[cfg(feature = "tmux_0_8")]
if let Some(target_client) = self.target_client {
cmd.push_option(T_LOWERCASE_KEY, target_client);
}
#[cfg(feature = "tmux_3_3")]
if let Some(prompt_type) = self.prompt_type {
cmd.push_option(T_UPPERCASE_KEY, prompt_type.to_string());
}
#[cfg(feature = "tmux_0_8")]
if let Some(template) = self.template {
cmd.push_param(template);
}
cmd
}
}