use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Bind<'a> = BindKey<'a>;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct BindKey<'a> {
#[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_4")))]
pub command_mode: bool,
#[cfg(feature = "tmux_1_5")]
pub root: bool,
#[cfg(feature = "tmux_1_5")]
pub repeat: bool,
#[cfg(feature = "tmux_3_1")]
pub note: Option<Cow<'a, str>>,
#[cfg(all(feature = "tmux_2_3", not(feature = "tmux_2_4")))]
pub repeat_count: Option<Cow<'a, str>>,
#[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>>,
#[cfg(feature = "tmux_0_8")]
pub command: Option<Cow<'a, str>>,
#[cfg(feature = "tmux_0_8")]
pub arguments: Option<Cow<'a, str>>,
}
impl<'a> BindKey<'a> {
pub fn new() -> Self {
Default::default()
}
#[cfg(all(feature = "tmux_0_8", 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_1_5")]
pub fn repeat(mut self) -> Self {
self.repeat = true;
self
}
#[cfg(feature = "tmux_3_1")]
pub fn note<S: Into<Cow<'a, str>>>(mut self, note: S) -> Self {
self.note = Some(note.into());
self
}
#[cfg(all(feature = "tmux_2_3", not(feature = "tmux_2_4")))]
pub fn repeat_count<S: Into<Cow<'a, str>>>(mut self, repeat_count: S) -> Self {
self.repeat_count = Some(repeat_count.into());
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
}
#[cfg(feature = "tmux_0_8")]
pub fn command<S: Into<Cow<'a, str>>>(mut self, command: S) -> Self {
self.command = Some(command.into());
self
}
#[cfg(feature = "tmux_0_8")]
pub fn arguments<S: Into<Cow<'a, str>>>(mut self, arguments: S) -> Self {
self.arguments = Some(arguments.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(BIND_KEY);
#[cfg(all(feature = "tmux_0_8", 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_1_5")]
if self.repeat {
cmd.push_flag(R_LOWERCASE_KEY);
}
#[cfg(feature = "tmux_3_1")]
if let Some(note) = self.note {
cmd.push_option(N_UPPERCASE_KEY, note);
}
#[cfg(all(feature = "tmux_2_3", not(feature = "tmux_2_4")))]
if let Some(repeat_count) = self.repeat_count {
cmd.push_option(R_UPPERCASE_KEY, repeat_count);
}
#[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);
}
#[cfg(feature = "tmux_0_8")]
if let Some(command) = self.command {
cmd.push_param(command);
}
#[cfg(feature = "tmux_0_8")]
if let Some(arguments) = self.arguments {
cmd.push_param(arguments);
}
cmd
}
}