use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Send<'a> = SendKeys<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SendKeys<'a> {
#[cfg(feature = "tmux_3_1")]
pub expand_formats: bool,
#[cfg(feature = "tmux_3_0a")]
pub hex: bool,
#[cfg(feature = "tmux_3_4")]
pub client: bool,
#[cfg(feature = "tmux_1_7")]
pub disable_lookup: bool,
#[cfg(feature = "tmux_2_1")]
pub mouse_event: bool,
#[cfg(feature = "tmux_1_7")]
pub copy_mode: bool,
#[cfg(feature = "tmux_2_4")]
pub reset: bool,
#[cfg(feature = "tmux_2_4")]
pub repeat_count: Option<usize>,
#[cfg(feature = "tmux_3_4")]
pub target_client: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
pub target_window: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_2_4")]
pub target_pane: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_0_8")]
pub keys: Vec<Cow<'a, str>>,
}
impl<'a> SendKeys<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_3_1")]
pub fn expand_formats(mut self) -> Self {
self.expand_formats = true;
self
}
#[cfg(feature = "tmux_3_0a")]
pub fn hex(mut self) -> Self {
self.hex = true;
self
}
#[cfg(feature = "tmux_3_4")]
pub fn client(mut self) -> Self {
self.client = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn disable_lookup(mut self) -> Self {
self.disable_lookup = true;
self
}
#[cfg(feature = "tmux_2_1")]
pub fn mouse_event(mut self) -> Self {
self.mouse_event = true;
self
}
#[cfg(feature = "tmux_1_7")]
pub fn copy_mode(mut self) -> Self {
self.copy_mode = true;
self
}
#[cfg(feature = "tmux_2_4")]
pub fn reset(mut self) -> Self {
self.reset = true;
self
}
#[cfg(feature = "tmux_2_4")]
pub fn repeat_count(mut self, repeat_count: usize) -> Self {
self.repeat_count = Some(repeat_count);
self
}
#[cfg(feature = "tmux_3_4")]
pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
self.target_client = Some(target_client.into());
self
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
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_4")]
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 key<S: Into<Cow<'a, str>>>(mut self, key: S) -> Self {
self.keys.push(key.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SEND_KEYS);
#[cfg(feature = "tmux_3_1")]
if self.expand_formats {
cmd.push_flag(F_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_0a")]
if self.hex {
cmd.push_flag(H_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_3_4")]
if self.client {
cmd.push_flag(K_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.disable_lookup {
cmd.push_flag(L_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_2_1")]
if self.mouse_event {
cmd.push_flag(M_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_1_7")]
if self.copy_mode {
cmd.push_flag(R_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_2_4")]
if self.reset {
cmd.push_flag(X_UPPERCASE_KEY);
}
#[cfg(feature = "tmux_2_4")]
if let Some(repeat_count) = self.repeat_count {
cmd.push_option(N_UPPERCASE_KEY, repeat_count.to_string());
}
#[cfg(feature = "tmux_3_4")]
if let Some(target_client) = self.target_client {
cmd.push_option(C_LOWERCASE_KEY, target_client);
}
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
#[cfg(feature = "tmux_2_4")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
#[cfg(feature = "tmux_0_8")]
for key in self.keys {
cmd.push_param(key);
}
cmd
}
}