use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Unbind<'a> = UnbindKey<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct UnbindKey<'a> {
#[cfg(feature = "tmux_1_5")]
pub all: bool,
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_4")))]
pub command_mode: bool,
#[cfg(feature = "tmux_1_5")]
pub root: bool,
#[cfg(feature = "tmux_3_2")]
pub quiet: bool,
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
pub key_table: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
pub mode_table: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_2_1")]
pub key_table: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_0_8")]
pub key: Option<Cow<'a, str>>,
}
impl<'a> UnbindKey<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(feature = "tmux_1_5")]
pub fn all(mut self) -> Self {
self.all = true;
self
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_4")))]
pub fn command_mode(mut self) -> Self {
self.command_mode = true;
self
}
#[cfg(feature = "tmux_1_5")]
pub fn root(mut self) -> Self {
self.root = true;
self
}
#[cfg(feature = "tmux_3_2")]
pub fn quiet(mut self) -> Self {
self.quiet = true;
self
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
pub fn key_table<S: Into<Cow<'a, str>>>(mut self, key_table: S) -> Self {
self.key_table = Some(key_table.into());
self
}
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
pub fn mode_table<S: Into<Cow<'a, str>>>(mut self, mode_table: S) -> Self {
self.mode_table = Some(mode_table.into());
self
}
#[cfg(feature = "tmux_2_1")]
pub fn key_table<S: Into<Cow<'a, str>>>(mut self, key_table: S) -> Self {
self.key_table = Some(key_table.into());
self
}
#[cfg(feature = "tmux_0_8")]
pub fn key<S: Into<Cow<'a, str>>>(mut self, key: S) -> Self {
self.key = Some(key.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(UNBIND_KEY);
#[cfg(feature = "tmux_1_5")]
if self.all {
cmd.push_flag(A_LOWERCASE_KEY);
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_4")))]
if self.command_mode {
cmd.push_flag(C_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_1_5")]
if self.root {
cmd.push_flag(N_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_2")]
if self.quiet {
cmd.push_flag(Q_LOWERCASE_KEY);
}
#[cfg(all(feature = "tmux_1_5", not(feature = "tmux_2_0")))]
if let Some(key_table) = self.key_table {
cmd.push_option(T_LOWERCASE_KEY, key_table);
}
#[cfg(all(feature = "tmux_2_0", not(feature = "tmux_2_4")))]
if let Some(mode_table) = self.mode_table {
cmd.push_option(T_LOWERCASE_KEY, mode_table);
}
#[cfg(feature = "tmux_2_1")]
if let Some(key_table) = self.key_table {
cmd.push_option(T_UPPERCASE_KEY, key_table);
}
#[cfg(feature = "tmux_0_8")]
if let Some(key) = self.key {
cmd.push_param(key);
}
cmd
}
}