use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Popup<'a> = DisplayPopup<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct DisplayPopup<'a> {
#[cfg(feature = "tmux_3_3")]
pub no_border: bool,
#[cfg(feature = "tmux_3_2")]
pub close: bool,
#[cfg(feature = "tmux_3_2")]
pub close_on_exit: bool,
#[cfg(feature = "tmux_3_2")]
pub close_on_success: bool,
#[cfg(feature = "tmux_3_6")]
pub any_key_dismiss: bool,
#[cfg(feature = "tmux_3_6")]
pub disable_previous: bool,
#[cfg(feature = "tmux_3_3")]
pub border_lines: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_2")]
pub target_client: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_2")]
pub start_directory: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_3")]
pub environment: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_2")]
pub height: Option<usize>,
#[cfg(feature = "tmux_3_3")]
pub style: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_3")]
pub border_style: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_2")]
pub target_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_3")]
pub title: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_3_2")]
pub width: Option<usize>,
#[cfg(feature = "tmux_3_2")]
pub x: Option<usize>,
#[cfg(feature = "tmux_3_2")]
pub y: Option<usize>,
#[cfg(feature = "tmux_3_2")]
pub shell_command: Option<Cow<'a, str>>,
}
impl<'a> DisplayPopup<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_3_3")]
pub fn no_border(mut self) -> Self {
self.no_border = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn close(mut self) -> Self {
self.close = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn close_on_exit(mut self) -> Self {
self.close_on_exit = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn close_on_success(mut self) -> Self {
self.close_on_success = true;
self
}
#[cfg(feature = "tmux_3_6")]
pub fn any_key_dismiss(mut self) -> Self {
self.any_key_dismiss = true;
self
}
#[cfg(feature = "tmux_3_6")]
pub fn disable_previous(mut self) -> Self {
self.disable_previous = true;
self
}
#[cfg(feature = "tmux_3_3")]
pub fn border_lines<S: Into<Cow<'a, str>>>(mut self, border_lines: S) -> Self {
self.border_lines = Some(border_lines.into());
self
}
#[cfg(feature = "tmux_3_2")]
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_2")]
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_3")]
pub fn environment<S: Into<Cow<'a, str>>>(mut self, environment: S) -> Self {
self.environment = Some(environment.into());
self
}
#[cfg(feature = "tmux_3_2")]
pub fn height(mut self, height: usize) -> Self {
self.height = Some(height);
self
}
#[cfg(feature = "tmux_3_3")]
pub fn style<S: Into<Cow<'a, str>>>(mut self, style: S) -> Self {
self.style = Some(style.into());
self
}
#[cfg(feature = "tmux_3_3")]
pub fn border_style<S: Into<Cow<'a, str>>>(mut self, border_style: S) -> Self {
self.border_style = Some(border_style.into());
self
}
#[cfg(feature = "tmux_3_2")]
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_3_3")]
pub fn title<S: Into<Cow<'a, str>>>(mut self, title: S) -> Self {
self.title = Some(title.into());
self
}
#[cfg(feature = "tmux_3_2")]
pub fn width(mut self, width: usize) -> Self {
self.width = Some(width);
self
}
#[cfg(feature = "tmux_3_2")]
pub fn x(mut self, x: usize) -> Self {
self.x = Some(x);
self
}
#[cfg(feature = "tmux_3_2")]
pub fn y(mut self, y: usize) -> Self {
self.y = Some(y);
self
}
#[cfg(feature = "tmux_3_2")]
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(DISPLAY_POPUP);
#[cfg(feature = "tmux_3_3")]
if self.no_border {
cmd.push_flag(B_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.close {
cmd.push_flag(C_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.close_on_exit {
cmd.push_flag(E_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.close_on_success {
cmd.push_flag(EE_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_6")]
if self.any_key_dismiss {
cmd.push_flag(K_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_6")]
if self.disable_previous {
cmd.push_flag(N_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_3")]
if let Some(border_lines) = self.border_lines {
cmd.push_option(B_LOWERCASE_KEY, border_lines);
}
#[cfg(feature = "tmux_3_2")]
if let Some(target_client) = self.target_client {
cmd.push_option(C_LOWERCASE_KEY, target_client);
}
#[cfg(feature = "tmux_3_2")]
if let Some(start_directory) = self.start_directory {
cmd.push_option(D_LOWERCASE_KEY, start_directory);
}
#[cfg(feature = "tmux_3_3")]
if let Some(environment) = self.environment {
cmd.push_option(E_LOWERCASE_KEY, environment);
}
#[cfg(feature = "tmux_3_2")]
if let Some(height) = self.height {
cmd.push_option(H_LOWERCASE_KEY, height.to_string());
}
#[cfg(feature = "tmux_3_3")]
if let Some(style) = self.style {
cmd.push_option(S_LOWERCASE_KEY, style);
}
#[cfg(feature = "tmux_3_3")]
if let Some(border_style) = self.border_style {
cmd.push_option(S_UPPERCASE_KEY, border_style);
}
#[cfg(feature = "tmux_3_2")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
#[cfg(feature = "tmux_3_3")]
if let Some(title) = self.title {
cmd.push_option(T_UPPERCASE_KEY, title);
}
#[cfg(feature = "tmux_3_2")]
if let Some(width) = self.width {
cmd.push_option(W_LOWERCASE_KEY, width.to_string());
}
#[cfg(feature = "tmux_3_2")]
if let Some(x) = self.x {
cmd.push_option(X_LOWERCASE_KEY, x.to_string());
}
#[cfg(feature = "tmux_3_2")]
if let Some(y) = self.y {
cmd.push_option(Y_LOWERCASE_KEY, y.to_string());
}
#[cfg(feature = "tmux_3_2")]
if let Some(shell_command) = self.shell_command {
cmd.push_param(shell_command);
}
cmd
}
}